python / python/cpython

argparse - make return type from `add_subparsers` public

オープン
#101,503 コメント 10 件 リアクション 15 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib topic-typing type-feature
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

This issue was brought up and closed as part of issue # 41592.

The add_subparsers method returns a protected _SubParsersAction instance. To add a sub-parser, the public add_parser method of the protected _SubParsersAction instance must be used.

  1. It is unexpected to require the use of a public method of a protected class instance.
  2. The protected return type breaks type hinting because
    1. protected and should not be imported
    2. it is not available for import

Real world use case example:

sub_parsers_action = parser.add_subparsers(...)

def build_subcmd(sub_parsers_action: _SubParsersAction):
    ...

The ask is to make the type of whatever is returned from add_subparsers public.

Linked PRs
  • gh-157001

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

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

はじめの一歩

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

調査の方向性

argparse.ArgumentParser.add_subparsers から開始し、返される _SubParsersAction を、その公開メソッドである add_parser を含めて追跡します。リンク先の PR gh-157001 と、周辺の argparse の typing/API コンテキストを確認します。完了条件は、保護されたクラスをインポートせずに、返される型を型ヒントで公開利用できることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
cli
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

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

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