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 for optional as UnionType (Python >= 3.10) #739

Closed
wants to merge 1 commit into from

Conversation

mkomet
Copy link

@mkomet mkomet commented Jan 27, 2024

This resolves the issue #533

@mkomet mkomet force-pushed the mkomet/add-optional-uniontype branch 4 times, most recently from 7bba6a7 to 92d1179 Compare January 27, 2024 01:07
Signed-off-by: Meir Komet <mskomet1@gmail.com>
@mkomet mkomet force-pushed the mkomet/add-optional-uniontype branch from 92d1179 to 311dfaa Compare January 27, 2024 09:27
@mkomet mkomet changed the title Support for optional as UnionType (Python > 3.10) Support for optional as UnionType (Python >> 3.10) Jan 27, 2024
@mkomet mkomet changed the title Support for optional as UnionType (Python >> 3.10) Support for optional as UnionType (Python >= 3.10) Jan 28, 2024
@svlandeg svlandeg added feature New feature, enhancement or request p3 types Type hints and type checking labels Feb 28, 2024
@johnthagen
Copy link

Also closes

Another PR that also address this issue

@@ -816,8 +822,9 @@ def get_click_param(
is_tuple = False
parameter_type: Any = None
is_flag = None
is_union_type = lenient_issubclass(type(main_type), UnionType)

Choose a reason for hiding this comment

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

Hi, I'm new to this kind of stuff, could you please clarify this for me please? From the variable name, it is a type already, why do we need to convert it to type() here? Is it just your preference or there are some edge cases being handled implicitly here?

@johnthagen johnthagen mentioned this pull request May 2, 2024
3 tasks
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.

Hi, thanks for this PR!

There's a few other PRs that address the same issue, of which I think #548 would be the prime candidate to merge. That PR uses existing functionality such as utils.needs_py310 and ._typing.is_union. If we merge #548, I think we can go ahead and close this one.

I'll leave the final decision with Tiangolo though.

@svlandeg svlandeg linked an issue May 21, 2024 that may be closed by this pull request
7 tasks
@svlandeg svlandeg added bug Something isn't working p2 and removed feature New feature, enhancement or request p3 labels May 21, 2024
@tiangolo
Copy link
Member

Thank you for the work @mkomet! ☕

And thanks @svlandeg for the help 🙇

This should have been fixed by #548

It is now available in Typer 0.12.4 🚀

Given that, I'll close this one.

@tiangolo tiangolo closed this Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2 types Type hints and type checking
Projects
None yet
5 participants