pypae / pydantic-typer

Typer extension to enable pydantic support
MIT License
3 stars 0 forks source link

Support for Union types #7

Closed pypae closed 2 weeks ago

pypae commented 2 weeks ago

Currently typer does not support union types. See this issue, and this comment in particular:

Is there any workaround for this currently? I've got a usecase where I need to be able to accept any of bool | str | float | int in a data science CLI application. I'm taking a str and using literal_eval to cast it back to its original type. Is there a better option?

Originally posted by @echus in https://github.com/fastapi/typer/issues/461#issuecomment-2230415249

Using pydantic.TypeAdapter to parse them can be implemented quite easily.