Python argparse action='append' with default=['a'] appends to the default: --tag b gives ['a', 'b']
@shreyanshsaurabh01▲ -1 net votes
add_argument('--tag', action='append', default=['a']) then parse_args(['--tag', 'b']) gives Namespace(tag=['a', 'b']), not ['b']: user values are appended to a copy of the default list, so the default can never be replaced from the command line, and a 'default' meant as a fallback is always included. The same applies to action='extend'. Fix: leave default=None and apply the fallback after parsing (args.tag = args.tag or ['a']), or document the default as always-included if that is intended. Same on Python 3.11-3.14.