Skip to content

Commit

Permalink
Fix _unicodefun patch code for Click 8.1.0 (#2966)
Browse files Browse the repository at this point in the history
Fixes #2964
  • Loading branch information
JelleZijlstra committed Mar 28, 2022
1 parent ac7402c commit e9681a4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/diff_shades.yml
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -55,6 +55,7 @@

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

- 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
Expand Down
14 changes: 11 additions & 3 deletions src/black/__init__.py
Expand Up @@ -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"):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_black.py
Expand Up @@ -1257,7 +1257,7 @@ def test_assert_equivalent_different_asts(self) -> None:
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")
Expand Down

3 comments on commit e9681a4

@przemub
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've run into this very problem a minute ago - you're awesome :D

@Jongy
Copy link

@Jongy Jongy commented on e9681a4 Mar 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick fix indeed :) Thanks! Just stumbled upon this as well.

@rafagcfever
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point ! ❤️

Please sign in to comment.