From e9681a40dcb3d38b56b301d811bb1c55201fd97e Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 28 Mar 2022 12:01:13 -0700 Subject: [PATCH] Fix _unicodefun patch code for Click 8.1.0 (#2966) Fixes #2964 --- .github/workflows/diff_shades.yml | 4 ++-- CHANGES.md | 1 + src/black/__init__.py | 14 +++++++++++--- tests/test_black.py | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/diff_shades.yml b/.github/workflows/diff_shades.yml index 51fcebc..0529b13 100644 --- a/.github/workflows/diff_shades.yml +++ b/.github/workflows/diff_shades.yml @@ -24,7 +24,7 @@ jobs: - name: Install diff-shades and support dependencies run: | - python -m pip install click packaging urllib3 + python -m pip install 'click<8.1.0' packaging urllib3 python -m pip install https://github.com/ichard26/diff-shades/archive/stable.zip - name: Calculate run configuration & metadata @@ -59,7 +59,7 @@ jobs: - name: Install diff-shades and support dependencies run: | python -m pip install https://github.com/ichard26/diff-shades/archive/stable.zip - python -m pip install click packaging urllib3 + python -m pip install 'click<8.1.0' packaging urllib3 python -m pip install -r .github/mypyc-requirements.txt # After checking out old revisions, this might not exist so we'll use a copy. cat scripts/diff_shades_gha_helper.py > helper.py diff --git a/CHANGES.md b/CHANGES.md index d34bd4e..02327fc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -55,6 +55,7 @@ +- Fix Black to work with Click 8.1.0 (#2966) - On Python 3.11 and newer, use the standard library's `tomllib` instead of `tomli` (#2903) - `black-primer`, the deprecated internal devtool, has been removed and copied to a diff --git a/src/black/__init__.py b/src/black/__init__.py index a82cf6a..e9d3c1b 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -1427,13 +1427,21 @@ def patch_click() -> None: file paths is minimal since it's Python source code. Moreover, this crash was spurious on Python 3.7 thanks to PEP 538 and PEP 540. """ + modules: List[Any] = [] try: from click import core + except ImportError: + pass + else: + modules.append(core) + try: from click import _unicodefun - except ModuleNotFoundError: - return + except ImportError: + pass + else: + modules.append(_unicodefun) - for module in (core, _unicodefun): + for module in modules: if hasattr(module, "_verify_python3_env"): module._verify_python3_env = lambda: None # type: ignore if hasattr(module, "_verify_python_env"): diff --git a/tests/test_black.py b/tests/test_black.py index b1bf177..ce7bab2 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -1257,7 +1257,7 @@ class BlackTestCase(BlackBaseTestCase): def test_shhh_click(self) -> None: try: from click import _unicodefun - except ModuleNotFoundError: + except ImportError: self.skipTest("Incompatible Click version") if not hasattr(_unicodefun, "_verify_python3_env"): self.skipTest("Incompatible Click version") -- 2.39.2