Skip to content

Commit e9681a4

Browse files
Fix _unicodefun patch code for Click 8.1.0 (#2966)
Fixes #2964
1 parent ac7402c commit e9681a4

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

.github/workflows/diff_shades.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
- name: Install diff-shades and support dependencies
2626
run: |
27-
python -m pip install click packaging urllib3
27+
python -m pip install 'click<8.1.0' packaging urllib3
2828
python -m pip install https://github.com/ichard26/diff-shades/archive/stable.zip
2929
3030
- name: Calculate run configuration & metadata
@@ -59,7 +59,7 @@ jobs:
5959
- name: Install diff-shades and support dependencies
6060
run: |
6161
python -m pip install https://github.com/ichard26/diff-shades/archive/stable.zip
62-
python -m pip install click packaging urllib3
62+
python -m pip install 'click<8.1.0' packaging urllib3
6363
python -m pip install -r .github/mypyc-requirements.txt
6464
# After checking out old revisions, this might not exist so we'll use a copy.
6565
cat scripts/diff_shades_gha_helper.py > helper.py

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

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

58+
- Fix Black to work with Click 8.1.0 (#2966)
5859
- On Python 3.11 and newer, use the standard library's `tomllib` instead of `tomli`
5960
(#2903)
6061
- `black-primer`, the deprecated internal devtool, has been removed and copied to a

src/black/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,13 +1427,21 @@ def patch_click() -> None:
14271427
file paths is minimal since it's Python source code. Moreover, this crash was
14281428
spurious on Python 3.7 thanks to PEP 538 and PEP 540.
14291429
"""
1430+
modules: List[Any] = []
14301431
try:
14311432
from click import core
1433+
except ImportError:
1434+
pass
1435+
else:
1436+
modules.append(core)
1437+
try:
14321438
from click import _unicodefun
1433-
except ModuleNotFoundError:
1434-
return
1439+
except ImportError:
1440+
pass
1441+
else:
1442+
modules.append(_unicodefun)
14351443

1436-
for module in (core, _unicodefun):
1444+
for module in modules:
14371445
if hasattr(module, "_verify_python3_env"):
14381446
module._verify_python3_env = lambda: None # type: ignore
14391447
if hasattr(module, "_verify_python_env"):

tests/test_black.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ def test_assert_equivalent_different_asts(self) -> None:
12571257
def test_shhh_click(self) -> None:
12581258
try:
12591259
from click import _unicodefun
1260-
except ModuleNotFoundError:
1260+
except ImportError:
12611261
self.skipTest("Incompatible Click version")
12621262
if not hasattr(_unicodefun, "_verify_python3_env"):
12631263
self.skipTest("Incompatible Click version")

0 commit comments

Comments
 (0)