Skip to content

Allow click_type and parser with Union type annotations#1683

Open
anibali wants to merge 1 commit into
fastapi:masterfrom
anibali:feat/allow-union-type-with-custom-parser
Open

Allow click_type and parser with Union type annotations#1683
anibali wants to merge 1 commit into
fastapi:masterfrom
anibali:feat/allow-union-type-with-custom-parser

Conversation

@anibali
Copy link
Copy Markdown

@anibali anibali commented Apr 9, 2026

Previously, any parameter annotated with a Union type (e.g. int | str) would unconditionally hit an assertion error. This change skips that assertion when the parameter has a custom parser or click_type specified. In those cases Typer delegates parsing entirely to the caller, making the type annotation irrelevant for type resolution.

This PR addresses #1595 (comment) and #1595 (comment), giving users the ability to use union types if they also specify how they should be parsed/converted.

@svlandeg svlandeg added the feature New feature, enhancement or request label Apr 13, 2026
@github-actions github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label May 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

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

Labels

conflicts Automatically generated when a PR has a merge conflict feature New feature, enhancement or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants