mirror of
https://github.com/python/cpython.git
synced 2025-11-01 14:11:41 +00:00
bpo-40059: Add tomllib (PEP-680) (GH-31498)
This adds a new standard library module, `tomllib`, for parsing TOML. The implementation is based on Tomli (https://github.com/hukkin/tomli). ## Steps taken (converting `tomli` to `tomllib`) - Move everything in `tomli:src/tomli` to `Lib/tomllib`. Exclude `py.typed`. - Remove `__version__ = ...` line from `Lib/tomllib/__init__.py` - Move everything in `tomli:tests` to `Lib/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`: ```python import unittest from . import load_tests unittest.main() ``` - Add the following to `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. - Run `make regen-stdlib-module-names` - Create `Doc/library/tomllib.rst` and reference it in `Doc/library/fileformats.rst`
This commit is contained in:
parent
4d95fa1ac5
commit
591f6754b5
90 changed files with 1479 additions and 1 deletions
11
Lib/test/test_tomllib/data/valid/array/array-subtables.json
Normal file
11
Lib/test/test_tomllib/data/valid/array/array-subtables.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{"arr":
|
||||
{"type":"array","value":
|
||||
[
|
||||
{"subtab":
|
||||
{"val": {"type":"integer","value":"1"}
|
||||
}
|
||||
},
|
||||
{"subtab": {"val": {"type":"integer","value":"2"}}}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
[[arr]]
|
||||
[arr.subtab]
|
||||
val=1
|
||||
|
||||
[[arr]]
|
||||
[arr.subtab]
|
||||
val=2
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent-table": {
|
||||
"arr": {"type":"array","value":[{},{}]},
|
||||
"not-arr": {"type":"integer","value":"1"}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
[[parent-table.arr]]
|
||||
[[parent-table.arr]]
|
||||
[parent-table]
|
||||
not-arr = 1
|
Loading…
Add table
Add a link
Reference in a new issue