mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
#9351: set_defaults on subparser is no longer ignored if set on parent.
Before, if a default was set on the parent parser, any default for that variable set via set_defaults on a subparser would be ignored. Now the subparser set_defaults is honored. Patch by Jyrki Pullianinen.
This commit is contained in:
parent
685b3495e1
commit
7570cbdc6b
3 changed files with 18 additions and 1 deletions
|
@ -1122,7 +1122,14 @@ class _SubParsersAction(Action):
|
|||
# parse all the remaining options into the namespace
|
||||
# store any unrecognized options on the object, so that the top
|
||||
# level parser can decide what to do with them
|
||||
namespace, arg_strings = parser.parse_known_args(arg_strings, namespace)
|
||||
|
||||
# In case this subparser defines new defaults, we parse them
|
||||
# in a new namespace object and then update the original
|
||||
# namespace for the relevant parts.
|
||||
subnamespace, arg_strings = parser.parse_known_args(arg_strings, None)
|
||||
for key, value in vars(subnamespace).items():
|
||||
setattr(namespace, key, value)
|
||||
|
||||
if arg_strings:
|
||||
vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
|
||||
getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue