Skip to content

[argparse] Allow string actions in add_subparsers - #16318

Open
nightcityblade wants to merge 1 commit into
python:mainfrom
nightcityblade:fix/issue-16309
Open

[argparse] Allow string actions in add_subparsers#16318
nightcityblade wants to merge 1 commit into
python:mainfrom
nightcityblade:fix/issue-16309

Conversation

@nightcityblade

Copy link
Copy Markdown
Contributor

Fixes #16309

The runtime accepts registered action names as strings in ArgumentParser.add_subparsers, just as add_argument does. This widens both overloads to accept str | type[Action] and adds a regression test using the built-in parsers registration.

Tests:

  • pre-commit on both changed files: passed
  • mypy stub checks on Python 3.10 through 3.15: passed
  • stdlib regression tests on Python 3.10, 3.14, and 3.15: passed
  • targeted Pyright, ty, and pyrefly checks: passed
  • targeted stubtest for argparse with the repository allowlist: passed

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@donbarbos

Copy link
Copy Markdown
Contributor

Please remove the tests. In typeshed, we only add regression tests for functions and classes which are known to have caused complex problems in the past, or where stubs are difficult to get right. 100% test coverage for typeshed is neither necessary nor desirable, as it would lead to code duplication.

See tests/REGRESSION.md for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants