argparse - make return type from `add_subparsers` public
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at argparse.ArgumentParser.add_subparsers and trace the returned _SubParsersAction, including its public add_parser method. Review linked PR gh-157001 and the surrounding argparse typing/API context; done means the returned type is publicly usable for type hints without importing the protected class.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100