Skip to content

Commit 8391979

Browse files
committed
Merge branch 'main' into ap_command_spec
2 parents 1b99078 + 1288fb6 commit 8391979

2 files changed

Lines changed: 0 additions & 43 deletions

File tree

cmd2/argparse_utils.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -449,30 +449,6 @@ def _validate_completion_callable(self: argparse.Action, value: Any) -> Any:
449449
register_argparse_argument_parameter("nargs_range")
450450
register_argparse_argument_parameter("suppress_tab_hint")
451451

452-
############################################################################################################
453-
# Workaround for Python 3.15.0b1 argparse bug
454-
# _ColorlessTheme.__getattr__ incorrectly returns "" for non-public attributes, which breaks
455-
# protocols like copy.deepcopy().
456-
############################################################################################################
457-
458-
if sys.version_info >= (3, 15):
459-
460-
def _ColorlessTheme_getattr( # noqa: N802
461-
_self: argparse._ColorlessTheme, # type: ignore[name-defined]
462-
name: str,
463-
) -> Any:
464-
"""Patched __getattr__ that allows non-public lookups to fail correctly.
465-
466-
This matches the implementation in CPython for their next release.
467-
"""
468-
if name.startswith("_"):
469-
raise AttributeError(name)
470-
return ""
471-
472-
# If the bug still exists, then install the patch.
473-
if getattr(argparse._ColorlessTheme(), "__deepcopy__", None) == "": # type: ignore[attr-defined]
474-
argparse._ColorlessTheme.__getattr__ = _ColorlessTheme_getattr # type: ignore[attr-defined]
475-
476452

477453
############################################################################################################
478454
# Patch _ActionsContainer.add_argument to support more arguments

tests/test_argparse_utils.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -863,22 +863,3 @@ def test_deprecated_subcommand() -> None:
863863
# Verify it was removed from _deprecated set
864864
assert "old" not in subparsers_action._deprecated # type: ignore[attr-defined]
865865
assert "old_alias" not in subparsers_action._deprecated # type: ignore[attr-defined]
866-
867-
868-
@pytest.mark.skipif(
869-
sys.version_info < (3, 15),
870-
reason="_ColorlessTheme only exists in 3.15+",
871-
)
872-
def test_colorless_theme_monkeypatch() -> None:
873-
"""Test the _ColorlessTheme.__getattr__ monkey patch."""
874-
875-
# If this assertion fails, then the bug no longer exists and our patch wasn't installed.
876-
# We can remove the patch function and this test.
877-
assert argparse._ColorlessTheme.__getattr__ == argparse_utils._ColorlessTheme_getattr
878-
879-
# Our patch raises an Attribute error for non-public.
880-
with pytest.raises(AttributeError):
881-
getattr(argparse._ColorlessTheme(), "_fake") # noqa: B009
882-
883-
with pytest.raises(AttributeError):
884-
getattr(argparse._ColorlessTheme(), "__deepcopy__") # noqa: B009

0 commit comments

Comments
 (0)