You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue may already exists but I was unable to find an exact match. There are plenty of issues related to the PEP 604 syntax but none that are really about using typing.Union/typing.Optional/...
src/union.py:6: note: Revealed type is "Union[builtins.int, None]"
src/union.py:8: error: Argument 2 to "isinstance" has incompatible type "<typing special form>"; expected "_ClassInfo" [arg-type]
src/union.py:9: note: Revealed type is "Any"
src/union.py:11: error: Argument 2 to "isinstance" has incompatible type "<typing special form>"; expected "_ClassInfo" [arg-type]
src/union.py:12: note: Revealed type is "Any"
src/union.py:17: note: Revealed type is "Union[builtins.int, None]"
src/union.py:19: error: Parameterized generics cannot be used with class or instance checks [misc]
src/union.py:19: error: Argument 2 to "isinstance" has incompatible type "<typing special form>"; expected "_ClassInfo" [arg-type]
src/union.py:20: note: Revealed type is "Any"
Found 4 errors in 1 file (checked 1 source file)
Running the above with pyright:
.../src/union.py
.../src/union.py:6:17 - information: Type of "foo" is "int | None"
.../src/union.py:9:17 - information: Type of "foo" is "int | None"
.../src/union.py:12:17 - information: Type of "foo" is "int | None"
.../src/union.py:17:17 - information: Type of "foo" is "int | None"
.../src/union.py:20:17 - information: Type of "foo" is "int | None"
0 errors, 0 warnings, 5 informations
Summary:
when using the PEP 604-syntax the type is correctly narrowed to Union[builtins.int, None]
when using the typing.Union and/or typing.Optional syntax the type is not narrowed and remains Any (and errors are shown)
The text was updated successfully, but these errors were encountered:
Preamble
typing.Union
/typing.Optional
/...isinstance
doesn't work on type aliases that use a union #11673 / Fix isinstance with type aliases to PEP 604 unions #17371Feature
Example code
Output for the above with mypy v1.11.1:
Running the above with pyright:
Summary:
Union[builtins.int, None]
typing.Union
and/ortyping.Optional
syntax the type is not narrowed and remainsAny
(and errors are shown)The text was updated successfully, but these errors were encountered: