Bug report
Bug description:
Python 3.13.11 (main, Dec 6 2025, 08:52:52) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from argparse import ArgumentParser
>>> parser = ArgumentParser(exit_on_error=False)
>>> parser.add_argument('tags', nargs='*')
_StoreAction(option_strings=[], dest='tags', nargs='*', const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)
>>> parser.parse_args(['--timeout'])
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
parser.parse_args(['--timeout'])
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/argparse.py", line 1904, in parse_args
raise ArgumentError(None, msg)
argparse.ArgumentError: unrecognized arguments: --timeout
>>> parser.parse_args(['--timeout', '1'])
Traceback (most recent call last):
File "<python-input-4>", line 1, in <module>
parser.parse_args(['--timeout', '1'])
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/argparse.py", line 1904, in parse_args
raise ArgumentError(None, msg)
argparse.ArgumentError: unrecognized arguments: --timeout
>>> parser.parse_args(['--timeout 1'])
Namespace(tags=['--timeout 1'])
Note that in the last case, there was no complaint about --timeout or --timeout 1 being an unrecognized argument. It was simply silently treated as a positional argument, which seems wrong to me as it starts with two dashes.
Admittedly this is an edge case, but it's easy to hit by mistake when calling such a process with subprocess and a list of arguments, and not necessarily easy to debug.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Bug report
Bug description:
Note that in the last case, there was no complaint about
--timeoutor--timeout 1being an unrecognized argument. It was simply silently treated as a positional argument, which seems wrong to me as it starts with two dashes.Admittedly this is an edge case, but it's easy to hit by mistake when calling such a process with
subprocessand a list of arguments, and not necessarily easy to debug.CPython versions tested on:
3.13
Operating systems tested on:
Linux