This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients ALSchwalm, miss-islington, paul.j3, rhettinger
Date 2021-10-25.18:16:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1635185775.31.0.127064192707.issue45235@roundup.psfhosted.org>
In-reply-to
Content
I haven't studied or tested this change, but it looks like a partial retraction of

https://bugs.python.org/issue9351 
argparse set_defaults on subcommands should override top level set_defaults

Originally the main namespace was passed to the subparser.  Steven Bethard changed it so that the subparser got a fresh namespace, and all values were copied to the main namespace.

I and others raised the question of how it affected user provided values 

https://bugs.python.org/issue27859
argparse - subparsers does not retain namespace

Looks like this patch tries to solve some problems by moving the self._defaults step to the end of parser_know_args.  I view that change with some trepidation.  Handling defaults is tricky enough, with setting them at the start, but then only passing them through 'type' at the end if they still match the original strings.

Mostly I've been telling StackOverflow questioners that it best not to use the same argument 'dest' in both the main and subparsers.  Flags can be the same, but the 'dest' should be different to avoid conflicts over which default has priority.

Again, I haven't tested this change, but I have a gut feeling it could have backward compatibility issues.
History
Date User Action Args
2021-10-25 18:16:15paul.j3setrecipients: + paul.j3, rhettinger, miss-islington, ALSchwalm
2021-10-25 18:16:15paul.j3setmessageid: <1635185775.31.0.127064192707.issue45235@roundup.psfhosted.org>
2021-10-25 18:16:15paul.j3linkissue45235 messages
2021-10-25 18:16:15paul.j3create