python / python/cpython

argparse: long options with mixed prefix characters

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

@serhiy-storchaka đang làm issue này rồi.

Từ ngày 9/9/2025.

stdlib triaged type-bug type-feature
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ả

argparse supports alternate prefix characters. I believe that this is to support on/off switches like -x/+x and Windows-style options like /h (for complete emulation of the Windows command syntax we need support of the : separator and combining options like in dir /s/w/o/p/a:-d, but this is another story). I never seen even double alternate prefix character, like ++foo or //foo in the wild, but there is no issue with supporting this.

The problem is that this allows specifying options that use two different prefix character, like -+foo or +-foo. It is a problem because you cannot distinguish a sigle-dash option from a double-dash option without knowing prefix._chars. And its value is not always available (for example in the Action constructor). BooleanOptionalAction can recognize ++foo and +foo, but it is confused by +^foo (see #138692).

There are no existing tests for mixed alternate prefix characters. I suppose this is not an intentionally added feature, but just an implementation artifact. I think that we should revisit code and only interpret option as a "double-dash long option" if it starts with the same prefix character doubled. This may have no effect on common users, since -+foo can still be interpreted as a "single-dash long option" (with name "+foo"). We should ensure that single-dash long options are not second-class citizens (for example see #138697).

I'm not sure how to classify this issue or what action to take. This requires further research and experimentation. I'm leaving this as a reminder that something needs to be done.

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.