GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pdb CLI argument parsing errors with arguments to module targets · Issue #113548 · python/cpython

pdb CLI argument parsing errors with arguments to module targets #113548

New issue
Copy link
New issue
Copy link
Closed
Closed
pdb CLI argument parsing errors with arguments to module targets#113548
Copy link
Assignees
gaogaotiantian
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@vivster7
vivster7
opened on Dec 28, 2023
Issue body actions

Bug report

Bug description:

The pdb CLI is no longer correctly forwarding arguments to other tools.

Example reproduction:

  • It raises an error pdb: error: argument pyfile: not allowed with argument -m
vscode ➜ ~ $ docker run -it --rm python:3.13.0a2 python -m pdb -m calendar 1
usage: pdb [-h] [-c command] (-m module | pyfile) [args ...]
pdb: error: argument pyfile: not allowed with argument -m

Expected behavior:

  • It starts the pdb debugger.
vscode ➜ ~ $ docker run -it --rm python:3.12 python -m pdb -m calendar 1
> /usr/local/lib/python3.12/calendar.py(1)<module>()
-> """Calendar printing functions
(Pdb) 

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

  • gh-113548: Allow CLI arguments to pdb -m #113557

Activity

  1. vivster7
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Dec 28, 2023
  2. vivster7 commented on Dec 28, 2023

    @vivster7
    vivster7
    on Dec 28, 2023
    Author
    More actions

    #109165 introduced this regression.

    I think the core of the issue is we are trying to parse arguments that we just need to be forwarding. I think treating the -m argument like a boolean argument to indicate "module-mode" and using parse_known_args would be closest to mimicking the behavior of the previous getopt behavior.

  3. AlexWaygood
    assigned
    gaogaotiantian
    on Dec 28, 2023
  4. vivster7 commented on Dec 28, 2023

    @vivster7
    vivster7
    on Dec 28, 2023
    Author
    More actions

    The getopt() function stops processing options as soon as a non-option argument is encountered.

    https://docs.python.org/3/library/getopt.html#module-getopt

    This is the hardest behavior to reproduce in argparse. Even parse_known_args will break a tool that takes a -c option, because it'll be parsed as an argument to pdb instead. I think this might be an acceptable breaking change though to get rid of getopt.

    python -m pdb -m calendar -c foo would be an example command that used to pass the -c foo option to calendar. If we implement parse_known_args, then I think the way to make this work in the future would be python -m pdb -m calendar -- -c foo.

    We would only need to pass the -- when the subsequent tool uses -c or --command since those are possible options to pdb.

  5. gaogaotiantian
    changed the title [-]pdb CLI argument parsing errors with unknown args[/-] [+]pdb CLI argument parsing errors with arguments to module targets[/+] on Dec 28, 2023
  6. gaogaotiantian commented on Dec 28, 2023

    @gaogaotiantian
    gaogaotiantian
    on Dec 28, 2023
    Member
    More actions

    This is actually a symptom for the real serious issue - pdb can't deal with arguments to modules (-m) now.

    # This will fail
    ./python -m pdb -m calendar 1
    

    The problem is, with the current argument parsing method, 1 will be considered as the file to debug and it will conflict with -m. Making -m the boolean introduces other issues:

    1. The help message would be confusing
    2. Commands like ./python -m pdb calendar -m will execute successfully, which is confusing.

    As for the -c part, that's not an issue, because when you have ambiguous options, you have to use -- to separate them clearly, that's true for any CLI and is not a pdb specific issue.

    But yes, we need to figure out a way to deal with the arguments to -m and it just seems like we can't have a perfect solution with argparse. We need some tradeoff here.

  7. iritkatriel
    added a commit that references this issue on Mar 27, 2024

    gh-113548: Allow CLI arguments to `pdb -m` (#113557)

    b3e8c78
  8. gaogaotiantian commented on Mar 27, 2024

    @gaogaotiantian
    gaogaotiantian
    on Mar 27, 2024
    Member
    More actions

    Fixed in #113557

  9. gaogaotiantian
    closed this as completedon Mar 27, 2024
  10. NGRsoftlab
    added 2 commits that reference this issue on Apr 2, 2024

    Squashed commit of the following:

    1b5fe4c

    Squashed commit of the following:

    a016a54
  11. diegorusso
    added a commit that references this issue on Apr 17, 2024

    pythongh-113548: Allow CLI arguments to `pdb -m` (python#113557)

    500e666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @gaogaotiantian
    gaogaotiantian

Labels

type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.