From 455a7b44c4b951c4dbf9184553c858f6010dc649 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 1 Apr 2022 10:37:58 -0700 Subject: [PATCH 1/5] try-except tomllib import See #2965 I left the version check in place because mypy doesn't generally like try-excepted imports. --- src/black/files.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 From ce094ce18e4407504de19898e5575c24397fcc44 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 1 Apr 2022 10:39:36 -0700 Subject: [PATCH 2/5] changelog --- CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index f68bc8f1a99..3d37d27ca63 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 From 11dec2b407b78f0ad085f808bb3aca30cf1f9b30 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 1 Apr 2022 10:47:23 -0700 Subject: [PATCH 3/5] Update CHANGES.md --- CHANGES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3d37d27ca63..66e673ccac3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -39,8 +39,8 @@ -* Use `tomli` instead of `tomllib` on Python 3.11 builds where `tomllib` - is not available (#2987) +* Use `tomli` instead of `tomllib` on Python 3.11 builds where `tomllib` is not + available (#2987) ### Parser From 90c8e735e9e3a0fb0db8ccf013dd1114f1f72608 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 1 Apr 2022 21:10:20 -0700 Subject: [PATCH 4/5] adjust setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'", From 4c9c697dbdc9ecdc18164249c5866e3fa98a53bf Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 1 Apr 2022 21:16:03 -0700 Subject: [PATCH 5/5] fix changelog --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 66e673ccac3..f2bdbd2e2b7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -39,7 +39,7 @@ -* Use `tomli` instead of `tomllib` on Python 3.11 builds where `tomllib` is not +- Use `tomli` instead of `tomllib` on Python 3.11 builds where `tomllib` is not available (#2987) ### Parser