Skip to content

argparse - make return type from add_subparsers public #101503

@highvelcty

Description

@highvelcty

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancement

    Projects

    Status

    Features

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions