Message402060
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. |
|
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 | |
|