python / python/cpython

Defaults conditionally omitted from help message when using ArgumentDefaultsHelpFormatter

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

Chưa có ai nhận issue này.

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

Mô tả

Bug report

Using ArgumentDefaultsHelpFormatter as formatter_class of ArgumentParser doesn't always shows default even if the default for argument is set. It's expected to show default if provided.

Example:

    parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
    parser.add_argument('foo', default=1)
    parser.add_argument('bar', nargs='*', default=1)
    parser.add_argument('baz', nargs='*', default=1, help='baz help')
    parser.add_argument('-a', default=1)
    parser.add_argument('-b', default=1, help='b_help')
    parser.print_help()

provides

positional arguments:
  foo
  bar
  baz         baz help (default: 1)

options:
  -h, --help  show this help message and exit
  -a A
  -b B        b_help (default: 1)

Though I see no reason to not show default for -a, foo and bar.
Making help argument mandatory to show default is necessary imho, but what is really strange is that it's enough for an option, but requires nargs for a positional argument.

Your environment

  • CPython versions tested on: 3.10.5
  • Operating system and architecture: Arch Linux x86_64 5.15.55-1-lts
Linked PRs
  • gh-112682

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.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện ví dụ ArgumentParser được cung cấp với ArgumentDefaultsHelpFormatter và kiểm tra hành vi của formatter đối với các đối số vị trí và tùy chọn. Kiểm tra PR gh-112682 được liên kết để xem phần việc hiện có; hoàn thành có nghĩa là đầu ra trợ giúp luôn hiển thị các giá trị mặc định được cung cấp trong các trường hợp được báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
cli
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
35/100

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.