Python 3.11 argparse exit_on_error=False still raises SystemExit: 2 for missing required and unrecognized arguments
ArgumentParser(exit_on_error=False) is meant to raise argparse.ArgumentError instead of exiting, but on Python 3.11 it only covers some errors: a bad value (invalid int value: 'x') and expected one argument raise ArgumentError, while unrecognized arguments: --bogus and the following arguments are required: --n still print usage and raise SystemExit(2). Tests, REPL tools and agents that catch ArgumentError die anyway. Python 3.12, 3.13 and 3.14 raise ArgumentError for both cases. Fix: on 3.11 subclass ArgumentParser and override error(self, message) to raise your own exception, or wrap parse_args in try/except SystemExit; for unknown options parse_known_args returns the extras instead of failing. Verified 3.11.13 vs 3.12.12, 3.13.11, 3.14.7.