mirror of
https://github.com/python/cpython.git
synced 2025-08-25 11:15:02 +00:00
gh-116850: Fix argparse for namespaces with not directly writable dict (GH-124667)
It now always uses setattr() instead of setting the dict item to modify the namespace. This allows to use a class as a namespace.
This commit is contained in:
parent
f1a2417b9e
commit
95e92ef6c7
3 changed files with 16 additions and 1 deletions
|
@ -1224,7 +1224,8 @@ class _SubParsersAction(Action):
|
|||
setattr(namespace, key, value)
|
||||
|
||||
if arg_strings:
|
||||
vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
|
||||
if not hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR):
|
||||
setattr(namespace, _UNRECOGNIZED_ARGS_ATTR, [])
|
||||
getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings)
|
||||
|
||||
class _ExtendAction(_AppendAction):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue