`argparse._SubParsersAction.add_parser` should default to `description` matching `help`
オープン
まだ誰も着手していません。
stdlib
type-feature
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Feature or enhancement
Proposal:
import argparse
# create the top-level parser
parser = argparse.ArgumentParser(prog='PROG')
parser.add_argument('--foo', action='store_true', help='foo help')
subparsers = parser.add_subparsers(help='subcommand help')
# create the parser for the "a" command
parser_a = subparsers.add_parser('a', help='a help')
parser_a.add_argument('bar', type=int, help='bar help')
# create the parser for the "b" command
parser_b = subparsers.add_parser('b', help='b help', description='b help')
parser_b.add_argument('--baz', choices=('X', 'Y', 'Z'), help='baz help')
# parse the args
print(parser.parse_args())
This currently produces:
gsnedders@gsnedders-margot tmp.IKpGQE2mE3 % python3.13 test.py --help
usage: PROG [-h] [--foo] {a,b} ...
positional arguments:
{a,b} subcommand help
a a help
b b help
options:
-h, --help show this help message and exit
--foo foo help
gsnedders@gsnedders-margot tmp.IKpGQE2mE3 % python3.13 test.py a --help
usage: PROG a [-h] bar
positional arguments:
bar bar help
options:
-h, --help show this help message and exit
gsnedders@gsnedders-margot tmp.IKpGQE2mE3 % python3.13 test.py b --help
usage: PROG b [-h] [--baz {X,Y,Z}]
b help
options:
-h, --help show this help message and exit
--baz {X,Y,Z} baz help
It would be nicer, however, if add_parser's description parameter defaulted to the value of the help argument.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
https://github.com/python/cpython/issues/89438 considered not outputting the value of help here to be a bug, but was closed because the description parameter also exists.
Linked PRs
- gh-135236
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
argparse._SubParsersAction.add_parser から始め、提案されている動作を理解するために、リンクされている PR gh-135236 を確認してください。サブパーサーがヘルプテキストをデフォルトの説明として使用し、明示的に指定された説明が引き続き有効であり、関連する argparse の動作がテストでカバーされていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- cli
- issue の種類
- 機能追加
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100