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

✨ Support common pydantic types #723

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

lachaib
Copy link

@lachaib lachaib commented Dec 21, 2023

This PR is "functional" as in "it does what was expected"

  • Support pydantic common types while keeping pydantic an optional dependency
  • Works in lists and tuples
  • Documentation with examples and test on examples

However, don't hesitate to request more tests, docs, or improvements on the code if needed to fit with the current standards

Fixes #181

Copy link

📝 Docs preview for commit 7ea8313 at: https://d7891fe3.typertiangolo.pages.dev

Copy link

📝 Docs preview for commit a36f24d at: https://9028cd14.typertiangolo.pages.dev

Copy link

📝 Docs preview for commit 23988ad at: https://4451bb64.typertiangolo.pages.dev

Copy link

📝 Docs preview for commit 08d1fac at: https://3976aef9.typertiangolo.pages.dev

@lachaib
Copy link
Author

lachaib commented Dec 21, 2023

@tiangolo in order to add a basic pydantic support, we'd need to drop python 3.6, and I'd say it's about time 😏
Would you agree with that? Do you want me to open another pull request to do so? I'd be glad to help.

Edit: seems it's already submitted here #556

@svlandeg svlandeg added feature New feature, enhancement or request p3 labels Feb 28, 2024
Copy link

📝 Docs preview for commit f6c2b03 at: https://1d1a6c3f.typertiangolo.pages.dev

@lachaib lachaib force-pushed the lachaib/issue181 branch 3 times, most recently from debccf1 to 2a48587 Compare March 28, 2024 22:36
@svlandeg
Copy link
Member

@tiangolo in order to add a basic pydantic support, we'd need to drop python 3.6, and I'd say it's about time 😏

Hi! Note that Python 3.6 support was recently dropped in 0.11.0.

@lachaib
Copy link
Author

lachaib commented Mar 29, 2024

@tiangolo in order to add a basic pydantic support, we'd need to drop python 3.6, and I'd say it's about time 😏

Hi! Note that Python 3.6 support was recently dropped in 0.11.0.

Yep I noticed that's why I rebased my PR yesterday 😁
Now the docs can't build in CI and I don't control it 😓

@svlandeg
Copy link
Member

svlandeg commented Mar 29, 2024

Now the docs can't build in CI and I don't control it 😓

There's an issue with the documentation building on the CI, unrelated to this PR. We're looking into it!

[UPDATE] docs building CI error is fixed.

Copy link

github-actions bot commented Apr 2, 2024

📝 Docs preview for commit 19319c6 at: https://99282d37.typertiangolo.pages.dev

@pypae pypae mentioned this pull request Apr 24, 2024
7 tasks
@pypae
Copy link

pypae commented Apr 26, 2024

Looks great, I'd love to see this get merged!

Could we somehow also support custom types defined by users like pydantic?

@lachaib
Copy link
Author

lachaib commented May 12, 2024

Looks great, I'd love to see this get merged!

Me too 😁

Could we somehow also support custom types defined by users like pydantic?

TBH I think this PR covers most of cases we need for now and I prefer to keep it minimalistic to get a chance for it to be merged soon.
On a personal project I managed to go a bit further and I'd really be glad to see Typer include all the features I made (some from inspiration of existing PRs) but small steps are always better.

Copy link

📝 Docs preview for commit fde3d16 at: https://6fef5bb9.typertiangolo.pages.dev

Copy link

📝 Docs preview for commit 2166319 at: https://ddf226eb.typertiangolo.pages.dev

Copy link

📝 Docs preview for commit 0ac6ec0 at: https://d8df500d.typertiangolo.pages.dev

Copy link

📝 Docs preview for commit 707839e at: https://ad610314.typertiangolo.pages.dev

@benglewis
Copy link

@tiangolo Is this PR being considered?

Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lachaib : I've internally solicited feedback from @tiangolo to decide on the direction of this work. The PR is in a good state to review and to assess what the added functionality would offer. But he'll need to decide whether we want to add this optional Pydantic dependency to Typer. I basically see three options:

  1. Add Pydantic as default, but optional dependency together with rich and shellingham (as in this PR)
  2. Add Pydantic as non-default, optional dependency through an additional install flag (this PR can be edited to do that)
  3. Don't add Pydantic as a dependency and not have this built-in support

If the third option is chosen, an alternative such as @pypae's recent WIP on pydantic-typer could be considered.

@lachaib
Copy link
Author

lachaib commented Jul 30, 2024

Given this feature is listed in the roadmap #678 , I pray this won't end up in option 3.
I've had a hack in my company's project for around as long as this PR's been opened and I'm looking forward to see it streamlined.
@tiangolo, as everything seems in your hands, don't hesitate to make a statement. I'm also available on discord if you want to discuss it.

@svlandeg svlandeg self-assigned this Aug 26, 2024
@svlandeg
Copy link
Member

svlandeg commented Aug 26, 2024

Slightly tricky merge conflict - I'll look into this and get this branch back up-to-date and green 🤞

Update: the test failure came from reverting an edit in this PR that changed the imports for get_args and get_origin to typing_extensions instead of _typing.py. I'd like to revisit such changes separately from all the functionality added here, and suggest to break that bit out to the PR #805.

@svlandeg svlandeg marked this pull request as draft August 26, 2024 12:32
@svlandeg svlandeg marked this pull request as ready for review August 26, 2024 13:27
@svlandeg svlandeg assigned tiangolo and unassigned svlandeg Aug 26, 2024
@lachaib
Copy link
Author

lachaib commented Sep 5, 2024

@pypae just so you know, I've tried to play a little bit yesterday night on getting this PR extended to support Custom Types, but the stack is stripping most annotations all the way down to the moment we're calling get_click_type and determine_type_convertor
There would be quite some additional changes to get there so I'm sticking with getting this PR done before extending it.

@svlandeg svlandeg removed their request for review September 9, 2024 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file feature New feature, enhancement or request p3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Support for common pydantic types
5 participants