You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use with_annotated decorator with custom types for allow easy type conversion #1688
When using the argparse approach (with_argparse decorator), the type argument of add_argument can be used for non-basic type conversion (see for example). The same is not possible when using the with_annotated decorator.
Possible design for a solution
Either allow custom types (as Typer does — see custom types) and make a best-effort type conversion for arbitrary annotations, or add an additional parameter to Option and Argument (for example conversion) that enables a two-step type conversion approach.
I will likely add a "converter" option. I am considering forbidding the use of the type argument within the metadata, since this kind of adds a chance of shooting yourself by accident, like doing a: Annotated[str, Argument(type=int)] which does not make sense.
Activity
KelvinChung2000 commentedon Jun 10, 2026
I will likely add a "converter" option. I am considering forbidding the use of the
typeargument within the metadata, since this kind of adds a chance of shooting yourself by accident, like doinga: Annotated[str, Argument(type=int)]which does not make sense.neoniobium commentedon Jun 10, 2026
Forbidding the use of the
typeargument within the metadata seems reasonable to me — I actually wondered about it while testing the decorator.