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

get_origin(str|None) != get_origin(Union[str,None]) #119302

Closed
moi90 opened this issue May 21, 2024 · 4 comments
Closed

get_origin(str|None) != get_origin(Union[str,None]) #119302

moi90 opened this issue May 21, 2024 · 4 comments
Labels
topic-typing type-bug An unexpected behavior, bug, or error

Comments

@moi90
Copy link
Contributor

moi90 commented May 21, 2024

Bug report

Bug description:

There seems to be a bug with str|None vs Union[str,None] / Optional[str]:

from typing import Union, get_origin

assert get_origin(str|None) == get_origin(Union[str,None])

get_origin(str|None)
# <class 'types.UnionType'>

get_origin(Union[str,None])
Union

This is unexpected to me and I think this is an error.

I verified this behavior on 3.10, 3.11 and 3.12.

CPython versions tested on:

3.10, 3.11, 3.12

Operating systems tested on:

Linux

@moi90 moi90 added the type-bug An unexpected behavior, bug, or error label May 21, 2024
@Eclips4
Copy link
Member

Eclips4 commented May 21, 2024

Hello!
There's no bug since it's really different types, although semantically they are the same.
After merge of #105511 this problem will gone.
cc @JelleZijlstra

@JelleZijlstra
Copy link
Member

Duplicate of #105499.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2024
@moi90
Copy link
Contributor Author

moi90 commented May 22, 2024

Thanks for the info! So currently, one needs to do get_origin(...) in (Union, UnionType) to check whether an annotation is any kind of union?

@Eclips4
Copy link
Member

Eclips4 commented May 22, 2024

Thanks for the info! So currently, one needs to do get_origin(...) in (Union, UnionType) to check whether an annotation is any kind of union?

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants