summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-11-12 18:44:25 (GMT)
committerGitHub <noreply@github.com>2021-11-12 18:44:25 (GMT)
commit587ff7f50bcbfd8346c6d5db459a1628a350c04d (patch)
tree6719e39328cb8ce3d490ca6532797bb64ebf14fb /Lib/argparse.py
parent8b6a474071bcc88ec3453e16f079181e551513c3 (diff)
downloadcpython-587ff7f50bcbfd8346c6d5db459a1628a350c04d.zip
cpython-587ff7f50bcbfd8346c6d5db459a1628a350c04d.tar.gz
cpython-587ff7f50bcbfd8346c6d5db459a1628a350c04d.tar.bz2
bpo-45235: Revert an argparse bugfix that caused a regression (GH-29525) (GH-29531)
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index cb5345d..7c28547 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -1209,8 +1209,7 @@ class _SubParsersAction(Action):
# namespace for the relevant parts.
subnamespace, arg_strings = parser.parse_known_args(arg_strings, None)
for key, value in vars(subnamespace).items():
- if not hasattr(namespace, key):
- setattr(namespace, key, value)
+ setattr(namespace, key, value)
if arg_strings:
vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
@@ -1844,6 +1843,11 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
if action.default is not SUPPRESS:
setattr(namespace, action.dest, action.default)
+ # add any parser defaults that aren't present
+ for dest in self._defaults:
+ if not hasattr(namespace, dest):
+ setattr(namespace, dest, self._defaults[dest])
+
# parse the arguments and exit if there are any errors
if self.exit_on_error:
try:
@@ -1854,11 +1858,6 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
else:
namespace, args = self._parse_known_args(args, namespace)
- # add any parser defaults that aren't present
- for dest in self._defaults:
- if not hasattr(namespace, dest):
- setattr(namespace, dest, self._defaults[dest])
-
if hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR):
args.extend(getattr(namespace, _UNRECOGNIZED_ARGS_ATTR))
delattr(namespace, _UNRECOGNIZED_ARGS_ATTR)