- Python Home
- About
- News
- Documentation
- Downloads
- Community
- Foundation
- Developer's Guide
- Issue Tracker
- Issues
- Summaries
- User
- Administration
- Help
➜
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 | ALSchwalm |
|---|---|
| Recipients | ALSchwalm |
| Date | 2021-09-17.14:58:54 |
| SpamBayes Score | -1.0 |
| Marked as misclassified | Yes |
| Message-id | <1631890734.12.0.701463144819.issue45235@roundup.psfhosted.org> |
| In-reply-to |
| Content |
|---|
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):
import argparse
parser = argparse.ArgumentParser()
sub = parser.add_subparsers()
example_subparser = sub.add_parser("example")
example_subparser.add_argument("--flag", default=10)
print(parser.parse_args(["example"], argparse.Namespace(flag=20)))
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. |
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2021-09-17 14:58:54 | ALSchwalm | set | recipients: + ALSchwalm |
| 2021-09-17 14:58:54 | ALSchwalm | set | messageid: <1631890734.12.0.701463144819.issue45235@roundup.psfhosted.org> |
| 2021-09-17 14:58:54 | ALSchwalm | link | issue45235 messages |
| 2021-09-17 14:58:54 | ALSchwalm | create |
Powered by Roundup Copyright © 1990-2022, Python Software Foundation
Legal Statements
