Skip to content

Commit

Permalink
try-except tomllib import (#2987)
Browse files Browse the repository at this point in the history
See #2965 

I left the version check in place because mypy doesn't generally like try-excepted imports.
  • Loading branch information
JelleZijlstra committed Apr 2, 2022
1 parent 5436810 commit 1af29fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
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

0 comments on commit 1af29fb

Please sign in to comment.