python / python/cpython

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

オープン
#156,577 コメント 4 件 リアクション 0 件 担当者 1 名 GitHub で見る

@picnixz がすでに取り組んでいます。

2026年9月1日 から。

docs stdlib type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。