Prevent crashes against valid 'pyproject.toml'. #1040
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
tomllibrary does not fully support the current TOML specification... in particular, arrays with items of heterogeneous types. Whentomlencounters things that it does not support, during load, it raises an exception which causes Yapf to crash in turn. Other tools inpyproject.tomlcan handle (and even expect) some of the things on whichtomlcrashes.The
tomlilibrary is noted as the inspiration for thetomllibmodule in Python 3.11+ standard library, according to PEP 680. Furthermore, the author oftomli(who is one of the PEP authors) is actively maintainingtomlifor backward compatibility at least until Python 3.10 reaches end-of-life, according to a statement in thetomlirepository:Where the package is actually being used in the code, I have elected to use
import tomli as tomllibto make it easier to switch totomllibonce 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 testbefore submitting this PR. Also verified directly that the command still runs correctly.