python / python/cpython

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

Đang mở
#156,577 4 bình luận 0 reaction 1 người được giao Xem trên GitHub

@picnixz đang làm issue này rồi.

Từ ngày 1/9/2026.

docs stdlib type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.