argparse - make return type from `add_subparsers` public
未關閉
還沒有人認領這個 Issue。
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.
- It is unexpected to require the use of a public method of a protected class instance.
- The protected return type breaks type hinting because
- protected and should not be imported
- 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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 argparse.ArgumentParser.add_subparsers 開始,追蹤回傳的 _SubParsersAction,包括其公開的 add_parser 方法。檢視相關的 PR gh-157001 以及 argparse 周邊的 typing/API 情境;完成的條件是:無需匯入受保護的類別,即可將回傳的型別公開用於型別提示。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- cli
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100