Skip to content

Support argument groups in add_argument_to typing - #256

Merged
casperdcl merged 1 commit into
tqdm:mainfrom
KapJI:type-add-argument-to-container
Aug 25, 2026
Merged

casperdcl merged 1 commit into
tqdm:mainfrom
KapJI:type-add-argument-to-container

Conversation

@KapJI

@KapJI KapJI commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

add_argument_to() calls add_argument() on the supplied object and then returns that same object. Argument groups support this operation at runtime, but the current ArgumentParser annotation rejects them.

Type the parameter using a TypeVar bounded by argparse's shared _ActionsContainer base. The bound permits parsers and argument groups, while the TypeVar preserves the concrete return type: passing an ArgumentParser returns anArgumentParser, and passing an _ArgumentGroup returns an _ArgumentGroup.

Add an annotated regression test covering an argument group.

@casperdcl casperdcl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@casperdcl
casperdcl merged commit 0a7c356 into tqdm:main Aug 25, 2026
2 checks passed
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.

2 participants