mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
bpo-45235: Revert an argparse bugfix that caused a regression (GH-29525) (GH-29530)
This commit is contained in:
parent
628667ac9a
commit
e4c5a5eaba
3 changed files with 9 additions and 13 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue