Skip to content

pdb: -- argument separator is rejected #148615

Closed

Description

@haampie

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

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Apr 15, 2026
  2. picnixz commented on Apr 15, 2026

    @picnixz
    Member
  3. Shrey-N commented on Apr 15, 2026

    @Shrey-N
    Contributor

    Hiya, I think you are right, this is a regression from the argparse switch in pdb added in PR gh-125115. since the pdb parser has no positional arguments defined, parser.parse_known_args() doesn't consume the -- separator and returns it in the remainder list. The manual post processing logic in parse_args() then incorrectly treats this -- as an unrecognized arg.

    I am working on a fix in parse_args() that checks for the -- separator. When found it would be popped from the argument list to mark the end of debugger options. :)

  4. added a commit that references this issue on May 6, 2026
  5. added a commit that references this issue on May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions