-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
(🐞) isinstance
works with typing.Union
s on 3.10+
#7505
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
Comments
The stubs look correct to me: Lines 1161 to 1172 in e8286e7
I believe that his is purely a mypy bug, but someone could correct me here. |
@srittau Thanks for the response! That stub doesn't contain anything about Could you please elaborate? |
Strictly speaking the I'm not sure this is really a problem that should be solved in the stubs, though. If we add |
@AlexWaygood Actually it's more specifically a I could make a pr when I get time. |
Cool, I'll happily take a look at a PR! In general I'm slightly leery of overcomplicating |
Something roughly like this: class _SpecialForm:
def __getitem__(self, typeargs: Any) -> object: ...
class _UnionSpecialForm(_SpecialForm):
def __getitem__(self, typeargs: Any) -> _UnionSpecialForm: ...
Union: _UnionSpecialForm = ... def isinstance(__obj: object, __class_or_tuple: type | types.UnionType | _UnionSpecialForm) -> bool: ... |
@AlexWaygood Here you go 😁 #7508 |
isinstance
works with typing.Union
sisinstance
works with typing.Union
s on 3.10+
The consensus in #7508 was that this was an unusual and niche use case, so it's probably best to close this as a "wontfix". |
Uh oh!
There was an error while loading. Please reload this page.
But this outputs
True
Union[X, Y]
is stubbed to returnobject
when it really returns atyping._UnionGenericAlias
totyping.Union
so that would need to be fixed first.playground
The text was updated successfully, but these errors were encountered: