Skip to content

Conversation

emcd
Copy link
Contributor

@emcd emcd commented Nov 30, 2022

  • Replace 'toml' dependency with 'tomli', which fully supports the current TOML specification.

The toml library does not fully support the current TOML specification... in particular, arrays with items of heterogeneous types. When toml encounters things that it does not support, during load, it raises an exception which causes Yapf to crash in turn. Other tools in pyproject.toml can handle (and even expect) some of the things on which toml crashes.

The tomli library is noted as the inspiration for the tomllib module in Python 3.11+ standard library, according to PEP 680. Furthermore, the author of tomli (who is one of the PEP authors) is actively maintaining tomli for backward compatibility at least until Python 3.10 reaches end-of-life, according to a statement in the tomli repository:

Tomli continues to provide a backport on PyPI for Python versions where the standard library module is not available and that have not yet reached their end-of-life.
Given this, tomli seems like the ideal replacement for toml.

Where the package is actually being used in the code, I have elected to use import tomli as tomllib to make it easier to switch to tomllib once Python 3.11 is the baseline supported version. In cases where the import is just being used a feature test, I simply added an "i" to the existing import with the belief that the feature tests can be removed once Python 3.11 is baseline.

In accordance with HACKING.rst, I ran:

  • PYTHONPATH=$PWD/yapf python3 -m yapf -i -r .
  • python3 setup.py test

before submitting this PR. Also verified directly that the command still runs correctly.

* Replace 'toml' dependency with 'tomli', which fully supports TOML 1.
@google-cla
Copy link

google-cla bot commented Nov 30, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@emcd
Copy link
Contributor Author

emcd commented Nov 30, 2022

I use my Github cloaked emails for commits but the CLA agreement manager detected my Gmail address. Will look into registering my cloaked email tomorrow. Actually, according the CLA docs, my Github username should be sufficient. Probably the CLA bot needs to be rerun.

@bwendling bwendling merged commit 5909ba8 into google:main Nov 30, 2022
@bwendling
Copy link
Member

Thanks!

Andrea-Oliveri pushed a commit to Andrea-Oliveri/yapf that referenced this pull request Aug 13, 2025
* Replace 'toml' dependency with 'tomli', which fully supports TOML 1.

Co-authored-by: Eric McDonald <emcd@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants