python / python/cpython

`pdb` consumes arguments greedily

Offen
#135,490 7 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@gaogaotiantian arbeitet bereits daran.

Seit 14.6.2025.

stdlib type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Bug report

Bug description:

I am reporting this bug on behalf of user Bradipo in #python on the Libera.chat IRC network. The user was trying to run a pytest quite with pdb and experiencing a confusing ImportError associated with the -m mark expression they were passing in.

It seems that the changes in 73ccfa2 (#109165) have changed the semantics of -m (and -c) so that any program being run with the debugger may not accept these arguments.

It is also worth mentioning that the traceback shown in the below reproduction does not manifest in the release build, which makes this problem harder to identify as there is no provenance for the error.

Reproduction

$ cat echo.py
import sys
print(sys.argv)
$ ./python -m pdb -m echo -m XYZ  # simulating running `pytest -m XYZ` with the debugger
Traceback (most recent call last):
  File "/home/jgerity/repos/cpython/Lib/pdb.py", line 166, in check
    self._details
  File "/home/jgerity/repos/cpython/Lib/functools.py", line 1014, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/home/jgerity/repos/cpython/Lib/pdb.py", line 174, in _details
    return runpy._get_module_details(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen runpy>", line 142, in _get_module_details
ImportError: No module named XYZ
$ ./python -c "import sys; print(sys.version)"
3.13.0a0 (bisect/bad:73ccfa28c5e, Jun 13 2025, 18:26:14) [GCC 12.3.0]

Expected behavior:

$ ./python -m pdb -m echo -m XYZ  # pdb prompt available at startup, -m in sys.argv
> /home/jgerity/repos/cpython/echo.py(1)<module>()
-> import sys
(Pdb) continue
['echo', '-m', 'XYZ']
The program finished and will be restarted
> /home/jgerity/repos/cpython/echo.py(1)<module>()
-> import sys
(Pdb) quit
$ ./python -c "import sys; print(sys.version)"  # AKA 73ccfa2~1
3.13.0a0 (tags/v3.12.0b1-1758-g3e8fcb7df74:3e8fcb7df74, Jun 13 2025, 18:32:54) [GCC 12.3.0]

with thanks to @nedbat for the excellent suggestion to use echo.py to cut pytest out of the reproduction.

CPython versions tested on:

3.13, 3.12

Operating systems tested on:

Linux

Linked PRs
  • gh-135520

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.