Skip to content

Use with_annotated decorator with custom types for allow easy type conversion #1688

Closed

Description

@neoniobium

Feature Request

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.

Activity

  1. KelvinChung2000 commented on Jun 10, 2026

    @KelvinChung2000
    Contributor

    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.

  2. neoniobium commented on Jun 10, 2026

    @neoniobium
    ContributorAuthor

    Forbidding the use of the type argument within the metadata seems reasonable to me — I actually wondered about it while testing the decorator.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions