Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix _unicodefun patch code for Click 8.1.0 #2966

Merged
merged 3 commits into from Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we pin < 8.1.0 if this fixes the bug? What am I missing - Is this for diff-shades?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There's another bug, pallets/click#2227

Copy link
Collaborator

Choose a reason for hiding this comment

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

Click 8.1.0 breaks mypyc (and probably mypy in general) as it both deleted internal APIs we import and also had a bad typing change (Jelle would have the link).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahh ok - I just read this below and was super confused as to why we pinned:

- Fix Black to work with Click 8.1.0 (#2966)

Cheers

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