- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 719
✨ Add support for custom types and parsers (updates/builds upon PR #443) #583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 Docs preview for commit fc0c382 at: https://64474ac4009f796c34b567ed--typertiangolo.netlify.app |
fc0c382
to
a390efe
Compare
📝 Docs preview for commit a390efe at: https://64474e485a84316be7974492--typertiangolo.netlify.app |
a390efe
to
8164eb5
Compare
📝 Docs preview for commit 8164eb5 at: https://644753af34d6486fedfb2ff5--typertiangolo.netlify.app |
📝 Docs preview for commit 5710188 at: https://644849696f71203299389a99--typertiangolo.netlify.app |
5710188
to
9116234
Compare
📝 Docs preview for commit 2b17b44 at: https://644851e3fbfcff3c834a32ea--typertiangolo.netlify.app |
2b17b44
to
24fd54f
Compare
📝 Docs preview for commit 4bf5dcb at: https://644853e5fd87a43c768966f3--typertiangolo.netlify.app |
4bf5dcb
to
21da75b
Compare
📝 Docs preview for commit eaab2ce at: https://6448576be1091d3e60a37c0f--typertiangolo.netlify.app |
eaab2ce
to
3ca8bf4
Compare
📝 Docs preview for commit 7567c9f at: https://6448598270ff0b3f40ceb477--typertiangolo.netlify.app |
7567c9f
to
bb333f7
Compare
📝 Docs preview for commit 27dd51b at: https://64485e4830ba04450ca61a5d--typertiangolo.netlify.app |
While most CLI parameters are strings, ints, etc, we sometimes need custom types. Currently typer has no support for it (See fastapi#77), and while there are a few hacks, the likely solution is to add a 'str' argument and parse it inside the main function. This PR adds support for custom types in 3 different ways: - Manually specifying a `click_type` - Manually specifying a `parse` function - Using a Callable type annotation (It is very common for types to have a string constructor, like `int("1")`)
Typer supports parsing of cutom types with: - A user provided parser class - A click custom type parser
27dd51b
to
f6e1a85
Compare
📝 Docs preview for commit 7ec8cfe at: https://6448635609512442e0ad65ab--typertiangolo.netlify.app |
📝 Docs preview for commit d5f35e7 at: https://644f86f9fb164b79047b7fc7--typertiangolo.netlify.app |
Thank you @jpurviance and @paulo-raca! 🚀 🍰 🕺 I tweaked the docs and tests a bit. 🤓 I'll release this in the next few hours in Typer |
Built upon #443 and adds documentation. Related to #77
Add support for custom types:
parse
function can be provided to create the type.click.ParamType
parse can be provided to create the type.