Skip to content

Possible incorrect type hint for argparse.ArgumentParser.add_subparsers action argument #16309

Description

@ipilcher

According to the argparse documentation, The action argument of argparse.ArgumentParser.add_subparsers can accept anything that the argument of the same name in argparse.ArgumentParser.add_argument can take. This implies that the type hint for that argument should be str | type[Action], rather than the current type[Action].

Some basic testing seems to imply that this is, in fact, true.

>>> import argparse
>>> parser1 = argparse.ArgumentParser()
>>> subparsers1 = parser1.add_subparsers(dest='command', action='parsers')
>>> subparsers1.add_parser('build')
ArgumentParser(prog=' build', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions