Skip to content

gh-148615: Handle -- end-of-options separator in pdb argument parsing#148624

Open
Shrey-N wants to merge 3 commits intopython:mainfrom
Shrey-N:e
Open

gh-148615: Handle -- end-of-options separator in pdb argument parsing#148624
Shrey-N wants to merge 3 commits intopython:mainfrom
Shrey-N:e

Conversation

@Shrey-N
Copy link
Copy Markdown
Contributor

@Shrey-N Shrey-N commented Apr 15, 2026

The switch from getopt to argparse in gh-125115, python -m pdb rejects the standard -- end-of-options separator. Makes it impossible to pass arguments that share names with pdb flags (like -c) to the target script.

The root cause is that pdb's argparse parser has no positional arguments defined, so parse_known_args() does not consume -- and returns it in the remainder list. The manual post processing logic in parse_args() then incorrectly treats it as an unrecognized flag since it starts with -.

This adds a check for -- in the elif args[0].startswith('-'). When found, the separator is consumed and parsing continues to the script name. If no script follows, an error is raised. All other unrecognized flags continue to produce the existing error message.

Closes gh-148615 :)

@gaogaotiantian
Copy link
Copy Markdown
Member

Thanks for fixing this. We need some regression test on this. We need to test the specific case reported, and also some others. I wonder if -- works as expected when it's on other places.

For the code itself, let's move -- check to it's own case (not under args[0].startswith), less nested logic.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pdb: -- argument separator is rejected

3 participants