@@ -277,7 +277,7 @@ def main(
277277
278278def 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
300310def patched_main () -> None :
301311 patch_click ()
302- main ()
312+ main () # type: ignore [misc]
303313
304314
305315if __name__ == "__main__" :
0 commit comments