bpo-40059: tomllib by hukkin · Pull Request #31498 · python/cpython
This adds a new standard library module, tomllib, for parsing TOML. The recently accepted PEP 680 -- tomllib is relevant here.
This PR has already seen some review in a PR under my personal fork: hukkin#2 (thanks to @encukou, @merwok, @hauntsaninja, @JelleZijlstra (I hope I'm not forgetting anyone)).
The implementation is based on Tomli which I plan to keep maintaining as a backport for Python versions 3.7, 3.8, 3.9 and 3.10, until finally Python 3.10 goes EOL.
Steps taken (converting tomli to tomllib)
-
Move everything in
tomli:src/tomlitoLib/tomllib. Excludepy.typed. -
Remove
__version__ = ...line fromLib/tomllib/__init__.py -
Move everything in
tomli:teststoLib/test/test_tomllib. Exclude the following test data dirs recursively:tomli:tests/data/invalid/_external/tomli:tests/data/valid/_external/
-
Create
Lib/test/test_tomllib/__main__.py:import unittest from . import load_tests unittest.main()
-
Add the following to
Lib/test/test_tomllib/__init__.py: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 tomllibtoimport tomllib. -
In
cpython/Lib/tomllib/_parser.pyreplace__fpwithfpand__swiths. Add the/toloadandloadsfunction signatures. -
Run
make regen-stdlib-module-names -
Create
Doc/library/tomllib.rstand reference it inDoc/library/fileformats.rst
edit: For reference, there's one more step – Add tomllib to Makefile.pre.in