Repository navigation
Open
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = None
created_at = <Date 2021-09-17.14:58:54.103>
labels = ['type-bug', '3.8', '3.9', '3.10', '3.11', '3.7', 'library']
title = 'argparse does not preserve namespace with subparser defaults'
updated_at = <Date 2021-12-22.19:20:37.779>
user = 'https://github.com/ALSchwalm'bugs.python.org fields:
activity = <Date 2021-12-22.19:20:37.779>
actor = 'gvanrossum'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2021-09-17.14:58:54.103>
creator = 'ALSchwalm'
dependencies = []
files = []
hgrepos = []
issue_num = 45235
keywords = ['patch']
message_count = 23.0
messages = ['402060', '402120', '402121', '402122', '404990', '404991', '405007', '405129', '406052', '406079', '406121', '406123', '406128', '406171', '406172', '406175', '406186', '406231', '406232', '406233', '406571', '406814', '408991']
nosy_count = 10.0
nosy_names = ['rhettinger', 'lukasz.langa', 'paul.j3', 'pablogsal', 'miss-islington', 'Frost Ming', 'RhinosF1', 'ALSchwalm', 'dgw', 'lwalejko']
pr_nums = ['28420', '28442', '28443', '29525', '29530', '29531', '29574', '30219']
priority = 'normal'
resolution = None
stage = 'patch review'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue45235'
versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBugs
- StatusShow more project fieldsNo status
Activity
ALSchwalm commentedon Sep 17, 2021
The following snippet demonstrates the problem. If a subparser flag has a default set, argparse will override the existing value in the provided 'namespace' if the flag does not appear (e.g., if the default is used):
This should return 'Namespace(flag=20)' because 'flag' already exists in the namespace, but instead it returns 'Namespace(flag=10)'. This intended behavior is described and demonstrated in the second example here: https://docs.python.org/3/library/argparse.html#default
Lib's behavior is correct for the non-subparser cause.
27 remaining items
FrostMing commentedon Nov 23, 2021
Hi, I noticed this bug because of the regression of Python 3.9.8. And I proposed a better approach in PR 29574.
Maybe the folks here can have a look. Thanks
FrostMing commentedon Dec 21, 2021
Per the review comments of @jiasli, I worked out a second PR to fix this issue.
This fix has less side-effect and better backward compatibility. I will leave the two PRs open. Any feedback is welcome.
patman: Fix defaults not propagating to subparsers
patman: Fix defaults not propagating to subparsers