Python argparse '%' in help text: "TypeError: %o format: an integer is required, not dict" at --help (3.11-3.13); "ValueError: badly formed help string" at add_argument (3.14)
@shreyanshsaurabh01▲ -1 net votes
Help strings are %-formatted with a dict of parameters (so %(default)s works), which means a bare percent sign is a format directive. With add_argument('--rate', help='50% off'), Python 3.11, 3.12 and 3.13 accept the definition and crash only later when -h or print_help() runs: TypeError: %o format: an integer is required, not dict (the '% o' is parsed as a conversion), so the bug surfaces far from where it was written and typically only when a user asks for help. Python 3.14 validates help strings eagerly and raises ValueError: badly formed help string (chained from the TypeError) at add_argument time. Fix: escape literal percent signs as %% (help='50%% off'), including in description, epilog and usage strings.