python / python/cpython

Undocumented exception: argparse add_argument(action='store_true', metavar='...') raises TypeError

Offen
#156,577 4 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@picnixz arbeitet bereits daran.

Seit 01.9.2026.

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

Beschreibung

Documentation

Not 100% sure whether this is a bug or a documentation error, but the behavior is reasonable, so filing this as a documentation issue for now.

>>> from argparse import ArgumentParser
>>> parser = ArgumentParser()
>>> parser.add_argument('-v', metavar='VERBOSE', dest='verbose', action='store_true')
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    parser.add_argument('-v', metavar='VERBOSE', dest='verbose', action='store_true')
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.14/argparse.py", line 1539, in add_argument
    action = action_class(**kwargs)
TypeError: _StoreTrueAction.__init__() got an unexpected keyword argument 'metavar'

There is no indication in the documentation that this combination will raise an exception.

(FWIW, this behavior is inconsistent with action='store_const', which silently swallows metavar.)

AI Usage

Claude Code, with Opus 4.8, was used to identify and analyze this issue.

Linked PRs
  • gh-156620

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.