From b7b7ad6036665e57bf1e4e41dd6611b86b4af655 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Tue, 25 Oct 2022 10:07:56 +0300 Subject: [PATCH] Update docs post Python 3.11 (#209) * Post py311 readme update * Add document for tomllib --- README.md | 10 ++++------ tomllib.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 tomllib.md diff --git a/README.md b/README.md index 24af867..6f4b78d 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ Tomli is a Python library for parsing [TOML](https://toml.io). It is fully compatible with [TOML v1.0.0](https://toml.io/en/v1.0.0). -A version of Tomli, the new `tomllib` module, -will be added to the standard library in Python 3.11 +A version of Tomli, the `tomllib` module, +was added to the standard library in Python 3.11 via [PEP 680](https://www.python.org/dev/peps/pep-0680/). Tomli continues to provide a backport on PyPI for Python versions where the standard library module is not available @@ -150,10 +150,8 @@ tomllib.loads("['This parses fine with Python 3.6+']") 2.3x as fast as [toml](https://pypi.org/project/toml/) - outputs [basic data types](#how-do-toml-types-map-into-python-types) only - 100% spec compliant: passes all tests in - [a test set](https://github.com/toml-lang/compliance/pull/8) - soon to be merged to the official - [compliance tests for TOML](https://github.com/toml-lang/compliance) - repository + [BurntSushi/toml-test](https://github.com/BurntSushi/toml-test) + test suite - thoroughly tested: 100% branch coverage ### Is comment preserving round-trip parsing supported? diff --git a/tomllib.md b/tomllib.md new file mode 100644 index 0000000..39dcabc --- /dev/null +++ b/tomllib.md @@ -0,0 +1,55 @@ +# `tomllib` – Tomli in the standard library + +Tomli was added to the Python standard library in Python 3.11. + +Relevant links: + +- Python Issue Tracker: https://bugs.python.org/issue40059 +- Tomli issue tracker: https://github.com/hukkin/tomli/issues/141 +- Discussion on PyPA "blessing" a TOML parser and/or including one in the standard library: https://discuss.python.org/t/adopting-recommending-a-toml-parser/4068 +- Python Enhancement Proposal: https://peps.python.org/pep-0680 +- CPython pull request: https://github.com/python/cpython/pull/31498 + +## Converting Tomli to tomllib + +### Sync status + +`tomllib` in CPython commit https://github.com/python/cpython/commit/deaf509e8fc6e0363bd6f26d52ad42f976ec42f2 +matches Tomli commit https://github.com/hukkin/tomli/commit/7e563eed5286b5d46b8290a9f56a86d955b23a9a + +### Steps to convert + +- Move everything in `tomli:src/tomli` to `cpython:Lib/tomllib`. Exclude `py.typed`. + +- Remove `__version__ = ...` line from `cpython:Lib/tomllib/__init__.py` + +- Move everything in `tomli:tests` to `cpython:Lib/test/test_tomllib`. Exclude the following test data dirs recursively: + + - `tomli:tests/data/invalid/_external/` + - `tomli:tests/data/valid/_external/` + +- Create `cpython:Lib/test/test_tomllib/__main__.py`: + + ```python + import unittest + + from . import load_tests + + + unittest.main() + ``` + +- Add the following to `cpython:Lib/test/test_tomllib/__init__.py`: + + ```python + import os + from test.support import load_package_tests + + + def load_tests(*args): + return load_package_tests(os.path.dirname(__file__), *args) + ``` + + Also change `import tomli as tomllib` to `import tomllib`. + +- In `cpython:Lib/tomllib/_parser.py` replace `__fp` with `fp` and `__s` with `s`. Add the `/` to `load` and `loads` function signatures.