Skip to content
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

✨ Add support for custom types and parsers (updates/builds upon PR #443) #583

Merged
merged 7 commits into from
May 1, 2023

Conversation

jpurviance
Copy link
Contributor

@jpurviance jpurviance commented Apr 25, 2023

Built upon #443 and adds documentation. Related to #77

Add support for custom types:

  • a parse function can be provided to create the type.
  • a click.ParamType parse can be provided to create the type.

@github-actions
Copy link

📝 Docs preview for commit fc0c382 at: https://64474ac4009f796c34b567ed--typertiangolo.netlify.app

@github-actions
Copy link

📝 Docs preview for commit a390efe at: https://64474e485a84316be7974492--typertiangolo.netlify.app

@github-actions
Copy link

📝 Docs preview for commit 8164eb5 at: https://644753af34d6486fedfb2ff5--typertiangolo.netlify.app

@github-actions
Copy link

📝 Docs preview for commit 5710188 at: https://644849696f71203299389a99--typertiangolo.netlify.app

@github-actions
Copy link

📝 Docs preview for commit 2b17b44 at: https://644851e3fbfcff3c834a32ea--typertiangolo.netlify.app

@github-actions
Copy link

📝 Docs preview for commit 4bf5dcb at: https://644853e5fd87a43c768966f3--typertiangolo.netlify.app

@github-actions
Copy link

📝 Docs preview for commit eaab2ce at: https://6448576be1091d3e60a37c0f--typertiangolo.netlify.app

@github-actions
Copy link

📝 Docs preview for commit 7567c9f at: https://6448598270ff0b3f40ceb477--typertiangolo.netlify.app

@github-actions
Copy link

📝 Docs preview for commit 27dd51b at: https://64485e4830ba04450ca61a5d--typertiangolo.netlify.app

paulo-raca and others added 2 commits April 25, 2023 17:31
While most CLI parameters are strings, ints, etc, we sometimes need custom
types.

Currently typer has no support for it (See tiangolo#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
@github-actions
Copy link

📝 Docs preview for commit 7ec8cfe at: https://6448635609512442e0ad65ab--typertiangolo.netlify.app

@tiangolo tiangolo changed the title Custom types [updates/builds upon #443] ✨ Add support for custom types and parsers [updates/builds upon PR #443] Apr 25, 2023
@tiangolo tiangolo changed the title ✨ Add support for custom types and parsers [updates/builds upon PR #443] ✨ Add support for custom types and parsers (updates/builds upon PR #443) May 1, 2023
@github-actions
Copy link

github-actions bot commented May 1, 2023

📝 Docs preview for commit d5f35e7 at: https://644f86f9fb164b79047b7fc7--typertiangolo.netlify.app

@tiangolo tiangolo merged commit 3e37e01 into tiangolo:master May 1, 2023
16 checks passed
@tiangolo
Copy link
Owner

tiangolo commented May 1, 2023

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 0.8.0. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants