Skip to content

Allow click_type and parser with Union type annotations#1683

Open
anibali wants to merge 1 commit intofastapi: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 intofastapi: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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature, enhancement or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants