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

try-except tomllib import #2987

Merged
merged 5 commits into from Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Expand Up @@ -39,6 +39,9 @@

<!-- Changes to how Black is packaged, such as dependency requirements -->

- Use `tomli` instead of `tomllib` on Python 3.11 builds where `tomllib` is not
available (#2987)

### Parser

<!-- Changes to the parser or to version autodetection -->
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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'",
Expand Down
6 changes: 5 additions & 1 deletion src/black/files.py
Expand Up @@ -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

Expand Down