Bug report
Bug description:
When using python -m pdb, it is impossible to pass arguments that share names with pdb flags (such as -c) to the target script:
python3 -m pdb -- script.py ...
Standard argparse behavior dictates using -- to separate parser arguments from script arguments, but pdb currently intercepts -- and crashes.
In old versions of Python (3.9) that used getopt for parsing, -- worked fine.
It seems to have regressed in Python 3.13, and #140933 does not fix it.
Reproducer
# Attempt to pass '-c' to the target script using '--'
python3 -m pdb -c continue -- my_script.py -c example
Expected behavior
pdb starts debugging my_script.py with sys.argv = ['my_script.py', '-c', "example"].
Actual behavior
usage: python3 -m pdb [-h] [-c command] (-m module | -p pid | pyfile) [args ...]
python3 -m pdb: error: unrecognized arguments: --
This is triggered by the following branch
elif args[0].startswith('-'):
# Invalid argument before the script name.
invalid_args = list(itertools.takewhile(lambda a: a.startswith('-'), args))
parser.error(f"unrecognized arguments: {' '.join(invalid_args)}")
that branch could possibly do something like:
elif args[0].startswith('-'):
if args[0] == '--':
args.pop(0) # Discard the separator
if not args:
parser.error("missing script or module to run")
else:
# Invalid argument before the script name.
invalid_args = list(itertools.takewhile(lambda a: a.startswith('-'), args))
parser.error(f"unrecognized arguments: {' '.join(invalid_args)}")
CPython versions tested on:
3.13, 3.14, 3.15, CPython main branch
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
When using
python -m pdb, it is impossible to pass arguments that share names withpdbflags (such as-c) to the target script:Standard
argparsebehavior dictates using--to separate parser arguments from script arguments, butpdbcurrently intercepts--and crashes.In old versions of Python (3.9) that used
getoptfor parsing,--worked fine.It seems to have regressed in Python 3.13, and #140933 does not fix it.
Reproducer
Expected behavior
pdbstarts debuggingmy_script.pywithsys.argv = ['my_script.py', '-c', "example"].Actual behavior
This is triggered by the following branch
that branch could possibly do something like:
CPython versions tested on:
3.13, 3.14, 3.15, CPython main branch
Operating systems tested on:
Linux
Linked PRs
--end-of-options separator in pdb argument parsing #148624