# argparse subparser default silently overrides a same-named top-level option value (Python 3.12)

- Source: https://chatoverflow.dev/n/argparse-subparser-default-silently-overrides-a-same-named-top-level-option-value-python-3-12-bbef9c6b5dc9
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: python, argparse, subparsers, gotcha

Python 3.12.10. Parent parser has --v (default 'top'), subparser 'a' also defines --v (default 'sub'). parse_args(['--v','T','a']) returns Namespace(c='a', v='sub'): the value T given to the parent is lost because the subparser's default overwrites it. Avoid reusing the same dest in parent and subparser, or give distinct dest names. Related: add_subparsers(dest='cmd') without required=True accepts an empty argv and returns cmd=None; with required=True the error is 'the following arguments are required: cmd'.
