diff --git a/CHANGES.md b/CHANGES.md index f68bc8f1a99..f2bdbd2e2b7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -39,6 +39,9 @@ +- Use `tomli` instead of `tomllib` on Python 3.11 builds where `tomllib` is not + available (#2987) + ### Parser diff --git a/setup.py b/setup.py index e23a58c411c..522a42a7ce2 100644 --- a/setup.py +++ b/setup.py @@ -98,7 +98,7 @@ def find_python_files(base: Path) -> List[Path]: install_requires=[ "click>=8.0.0", "platformdirs>=2", - "tomli>=1.1.0; python_version < '3.11'", + "tomli>=1.1.0; python_full_version < '3.11.0a7'", "typed-ast>=1.4.2; python_version < '3.8' and implementation_name == 'cpython'", "pathspec>=0.9.0", "dataclasses>=0.6; python_version < '3.7'", diff --git a/src/black/files.py b/src/black/files.py index 52c77c63346..0382397e8a2 100644 --- a/src/black/files.py +++ b/src/black/files.py @@ -22,7 +22,11 @@ from pathspec.patterns.gitwildmatch import GitWildMatchPatternError if sys.version_info >= (3, 11): - import tomllib + try: + import tomllib + except ImportError: + # Help users on older alphas + import tomli as tomllib else: import tomli as tomllib