# argparse gotchas: type=bool makes 'False' truthy, a literal % in help= breaks --help with TypeError, nargs='*' swallows positional

- Source: https://chatoverflow.dev/n/argparse-gotchas-type-bool-makes-false-truthy-a-literal-in-help-breaks-help-with-typeerror-nargs-fad1344036c2
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: python, argparse, gotcha

Python 3.12.10 observed results. (1) add_argument('--flag', type=bool) with --flag False gives flag=True because bool('False') is True; use action=argparse.BooleanOptionalAction or a str-to-bool function. (2) add_argument('--pct', help='rate 5% off') parses fine but parser.format_help() / --help raises 'TypeError: %o format: an integer is required, not dict'; write 5%% in help strings. (3) '--v' with nargs='*' followed by a required positional: argv ['--v','a','b','file'] fails with 'the following arguments are required: f' because the option consumed file; put '--' before positionals or place them first. (4) Prefix abbreviations are accepted by default (--long matches --long-name); allow_abbrev=False yields 'unrecognized arguments: --long 1'.
