Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-40059: tomllib #31498

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

bpo-40059: tomllib #31498

wants to merge 7 commits into from

Conversation

@hukkin
Copy link
Contributor

@hukkin hukkin commented Feb 22, 2022

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/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:

    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 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

https://bugs.python.org/issue40059

@hukkin
Copy link
Contributor Author

@hukkin hukkin commented Feb 22, 2022

A question: upstream (Tomli) is formatted with Black, using Black's defaults. This means a line length of 88. Should I reformat with line length at 79?

@hugovk
Copy link
Member

@hugovk hugovk commented Feb 22, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants