Skip to content

Commit 114e835

Browse files
authored
Remove click patch (#3768)
Apparently this was only needed on Python 3.6. We've now dropped support for 3.6 and 3.7. It's also not needed on new enough click.
1 parent 4130c65 commit 114e835

File tree

5 files changed

+1
-62
lines changed

5 files changed

+1
-62
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<!-- Changes to how Black is packaged, such as dependency requirements -->
4444

4545
- Upgrade mypyc from 0.991 to 1.3 (#3697)
46+
- Remove patching of Click that mitigated errors on Python 3.6 with `LANG=C` (#3768)
4647

4748
### Parser
4849

docs/contributing/reference/reference_functions.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ Utilities
165165

166166
.. autofunction:: black.linegen.normalize_invisible_parens
167167

168-
.. autofunction:: black.patch_click
169-
170168
.. autofunction:: black.nodes.preceding_leaf
171169

172170
.. autofunction:: black.re_compile_maybe_verbose

src/black/__init__.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,40 +1410,6 @@ def nullcontext() -> Iterator[None]:
14101410
yield
14111411

14121412

1413-
def patch_click() -> None:
1414-
"""Make Click not crash on Python 3.6 with LANG=C.
1415-
1416-
On certain misconfigured environments, Python 3 selects the ASCII encoding as the
1417-
default which restricts paths that it can access during the lifetime of the
1418-
application. Click refuses to work in this scenario by raising a RuntimeError.
1419-
1420-
In case of Black the likelihood that non-ASCII characters are going to be used in
1421-
file paths is minimal since it's Python source code. Moreover, this crash was
1422-
spurious on Python 3.7 thanks to PEP 538 and PEP 540.
1423-
"""
1424-
modules: List[Any] = []
1425-
try:
1426-
from click import core
1427-
except ImportError:
1428-
pass
1429-
else:
1430-
modules.append(core)
1431-
try:
1432-
# Removed in Click 8.1.0 and newer; we keep this around for users who have
1433-
# older versions installed.
1434-
from click import _unicodefun # type: ignore
1435-
except ImportError:
1436-
pass
1437-
else:
1438-
modules.append(_unicodefun)
1439-
1440-
for module in modules:
1441-
if hasattr(module, "_verify_python3_env"):
1442-
module._verify_python3_env = lambda: None
1443-
if hasattr(module, "_verify_python_env"):
1444-
module._verify_python_env = lambda: None
1445-
1446-
14471413
def patched_main() -> None:
14481414
# PyInstaller patches multiprocessing to need freeze_support() even in non-Windows
14491415
# environments so just assume we always need to call it if frozen.
@@ -1452,7 +1418,6 @@ def patched_main() -> None:
14521418

14531419
freeze_support()
14541420

1455-
patch_click()
14561421
main()
14571422

14581423

src/blackd/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ def parse_python_variant_header(value: str) -> Tuple[bool, Set[black.TargetVersi
225225
def patched_main() -> None:
226226
maybe_install_uvloop()
227227
freeze_support()
228-
black.patch_click()
229228
main()
230229

231230

tests/test_black.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,30 +1455,6 @@ def test_assert_equivalent_different_asts(self) -> None:
14551455
with self.assertRaises(AssertionError):
14561456
black.assert_equivalent("{}", "None")
14571457

1458-
def test_shhh_click(self) -> None:
1459-
try:
1460-
from click import _unicodefun # type: ignore
1461-
except ImportError:
1462-
self.skipTest("Incompatible Click version")
1463-
1464-
if not hasattr(_unicodefun, "_verify_python_env"):
1465-
self.skipTest("Incompatible Click version")
1466-
1467-
# First, let's see if Click is crashing with a preferred ASCII charset.
1468-
with patch("locale.getpreferredencoding") as gpe:
1469-
gpe.return_value = "ASCII"
1470-
with self.assertRaises(RuntimeError):
1471-
_unicodefun._verify_python_env()
1472-
# Now, let's silence Click...
1473-
black.patch_click()
1474-
# ...and confirm it's silent.
1475-
with patch("locale.getpreferredencoding") as gpe:
1476-
gpe.return_value = "ASCII"
1477-
try:
1478-
_unicodefun._verify_python_env()
1479-
except RuntimeError as re:
1480-
self.fail(f"`patch_click()` failed, exception still raised: {re}")
1481-
14821458
def test_root_logger_not_used_directly(self) -> None:
14831459
def fail(*args: Any, **kwargs: Any) -> None:
14841460
self.fail("Record created with root logger")

0 commit comments

Comments
 (0)