summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-09-29 08:01:10 (GMT)
committerGitHub <noreply@github.com>2024-09-29 08:01:10 (GMT)
commit95e92ef6c74e973ea13d15180190d0fa2af82fbf (patch)
tree4cc8698de8eb1fc631cbb3d567a6b52ca6d4c37f /Lib/argparse.py
parentf1a2417b9e2993e584610851ac004c8b0599b323 (diff)
downloadcpython-95e92ef6c74e973ea13d15180190d0fa2af82fbf.zip
cpython-95e92ef6c74e973ea13d15180190d0fa2af82fbf.tar.gz
cpython-95e92ef6c74e973ea13d15180190d0fa2af82fbf.tar.bz2
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.
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index a671c8b..5042891 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -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):