Skip to content

pdb: can't debug a script with arguments #125115

Closed

Description

@Jamim

Bug report

Bug description:

Hello everyone,

With Python 3.13, pdb doesn't pass arguments like -b or --bar to a script while it works fine with Python 3.12.

test.py

import sys

print(' '.join(sys.argv))

✅ Good:

$ python3.13 -m pdb -c continue -c quit test.py foo
test.py foo
The program finished and will be restarted

🐛 Bad:

$ python3.13 -m pdb -c continue -c quit test.py foo --bar
usage: pdb [-h] [-c command] (-m module | pyfile) [args ...]
pdb: error: unrecognized arguments: --bar

✅ Good:

$ python3.12 -m pdb -c continue -c quit test.py foo --bar
test.py foo --bar
The program finished and will be restarted

Best regards!

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Oct 8, 2024
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    3.13only security fixes
    on Oct 8, 2024
  3. gaogaotiantian commented on Oct 8, 2024

    @gaogaotiantian
    Member

    Yes that's a bug when pdb switched to argparse. I'll fix it but It would be in the next 3.13 release. In the meantime, you should be able to explicitly pass the argument to the script instead of pdb by ./python -m pdb -c continue -c quit -- test.py foo --bar

  4. added a commit that references this issue on Oct 15, 2024
  5. added a commit that references this issue on Oct 15, 2024
  6. gaogaotiantian commented on Oct 15, 2024

    @gaogaotiantian
    Member

    Fixed in #125424

  7. added a commit that references this issue on Oct 15, 2024
  8. added a commit that references this issue on Jan 12, 2025
  9. bulrush15 commented on Oct 28, 2025

    @bulrush15

    This is still an problem in Python 3.14.0.

  10. gaogaotiantian commented on Oct 29, 2025

    @gaogaotiantian
    Member

    @bulrush15 could you give a repro? What command did not work for you? The command above works for me on 3.14 and 3.15.

  11. bulrush15 commented on Oct 29, 2025

    @bulrush15

    I have Python 3.14.0 on Windows 2025 Datacenter edition v24H2.

    This python command fails: python -m pdb pacetool.py -pacetablescsv. Note the "-p" beginning of "-pacetablescsv". This seems to cause problems. The error this command gives is:

    usage: python.exe -m pdb [-h] [-c command] (-m module | -p pid | pyfile) [args ...]
    python.exe -m pdb: error: argument -p/--pid: invalid int value: 'acetablescsv'
    

    This command works. Note that no long option in this case begins with "-p": python -m pdb piecework.py -daily -test -adminemailonly

    Python 3.14: Also note that "-p" (lowercase) is not part of the python -h or python --help-all screens but uppercase "-P" is.

    These programs all worked fine on Python 3.11.9. These programs all work fine without "-m pdb". It's using pdb that's the issue. pdb seems to process command line options differently between Python 3.11.9 and Python 3.14.

    Make a project dir with an environment. You can make a totally fake program with a fake parameter to test it. Make a program "test.py" that contains:

    print("Hello world")
    

    Activate your environment and now do: python -m pdb test.py -pacetablescsv

  12. gaogaotiantian commented on Nov 3, 2025

    @gaogaotiantian
    Member

    The culprit here is -pacetablescsv. The command line argument convention for Python is to use a single dash (-) as "short options", which means it should take one letter. In this specific case, your command is equivalent (from argparse's view) as

    python -m pdb test.py -p acetablescsv
    

    -p is used by pdb to attach to a process, that's where the conflict is.

    I still believe that we can make this better. I need to think about it.

  13. added 2 commits that reference this issue on Nov 16, 2025
  14. added a commit that references this issue on Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.13only security fixesstdlibStandard 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