@@ -371,21 +371,27 @@ def _validate_completion_callable(self: argparse.Action, value: Any) -> Any:
371371
372372############################################################################################################
373373# Workaround for Python 3.15.0b1 argparse bug
374- # _ColorlessTheme.__getattr__ incorrectly returns "" for dunder methods , which breaks
374+ # _ColorlessTheme.__getattr__ incorrectly returns "" for non-public attributes , which breaks
375375# protocols like copy.deepcopy().
376376############################################################################################################
377377
378378if sys .version_info >= (3 , 15 ):
379379
380- def _ColorlessTheme_getattr (_self : argparse ._ColorlessTheme , name : str ) -> Any : # noqa: N802
381- """Patched __getattr__ that allows dunder lookups to fail correctly."""
382- if name .startswith ("__" ) and name .endswith ("__" ):
380+ def _ColorlessTheme_getattr ( # noqa: N802
381+ _self : argparse ._ColorlessTheme , # type: ignore[name-defined]
382+ name : str ,
383+ ) -> Any :
384+ """Patched __getattr__ that allows non-public lookups to fail correctly.
385+
386+ This matches the implementation in CPython for their next release.
387+ """
388+ if name .startswith ("_" ):
383389 raise AttributeError (name )
384390 return ""
385391
386392 # If the bug still exists, then install the patch.
387- if getattr (argparse ._ColorlessTheme (), "__deepcopy__" , None ) == "" :
388- argparse ._ColorlessTheme .__getattr__ = _ColorlessTheme_getattr
393+ if getattr (argparse ._ColorlessTheme (), "__deepcopy__" , None ) == "" : # type: ignore[attr-defined]
394+ argparse ._ColorlessTheme .__getattr__ = _ColorlessTheme_getattr # type: ignore[attr-defined]
389395
390396
391397############################################################################################################
0 commit comments