Skip to content

Commit 5bd2922

Browse files
authored
Update patch_click to fix compatibility issue with click 8.1.0. Fix #132 (#133)
1 parent e160568 commit 5bd2922

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

curlylint/cli.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def main(
277277

278278
def patch_click() -> None:
279279
"""Borrowed from black.
280-
https://github.com/psf/black/blob/959848c17639bfc646128f6b582c5858164a5001/black.py
280+
https://github.com/psf/black/blob/e9681a40dcb3d38b56b301d811bb1c55201fd97e/src/black/__init__.py#L1419-L1448
281281
Make Click not crash.
282282
On certain misconfigured environments, Python 3 selects the ASCII encoding as the
283283
default which restricts paths that it can access during the lifetime of the
@@ -286,20 +286,30 @@ def patch_click() -> None:
286286
file paths is minimal since it's Python source code. Moreover, this crash was
287287
spurious on Python 3.7 thanks to PEP 538 and PEP 540.
288288
"""
289+
modules: List[Any] = []
289290
try:
290291
from click import core
291-
from click import _unicodefun
292-
except ModuleNotFoundError:
293-
return
292+
except ImportError:
293+
pass
294+
else:
295+
modules.append(core)
296+
try:
297+
from click import _unicodefun # type: ignore [attr-defined]
298+
except ImportError:
299+
pass
300+
else:
301+
modules.append(_unicodefun)
294302

295-
for module in (core, _unicodefun):
303+
for module in modules:
296304
if hasattr(module, "_verify_python3_env"):
297-
module._verify_python3_env = lambda: None # type: ignore [attr-defined]
305+
module._verify_python3_env = lambda: None
306+
if hasattr(module, "_verify_python_env"):
307+
module._verify_python_env = lambda: None
298308

299309

300310
def patched_main() -> None:
301311
patch_click()
302-
main()
312+
main() # type: ignore [misc]
303313

304314

305315
if __name__ == "__main__":

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
black==22.1.0
1+
black==22.3.0
22
flake8==4.0.1
33
mypy==0.812
44
pytest==7.0.1

0 commit comments

Comments
 (0)