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
Expression of type "list[list[int]]" cannot be assigned to return type "matrix"
"list[list[int]]" is incompatible with "matrix"
TypeVar "_T@list" is invariant
"list[int]" is incompatible with "vector"
TypeVar "_T@list" is invariant
Type "int" cannot be assigned to type "float | int"
The text was updated successfully, but these errors were encountered:
djccnt15
changed the title
nested type hint with "Union" operator doesn't work properly
type hint with "Union" operator doesn't work properly
Nov 14, 2022
Yes, this behavior is correct. To understand why, please review this documentation about static type concepts.
There are two simple options for eliminating the type violation error:
Do not assign the intermediate value to variable I. Move the return keyword directly before the list comprehension. This allows pylance to use bidirectional type inference to infer the correct return type.
Supply a type declaration for intermediate variable I (I: matrix). This once again allows pylance to use bidirectional type inference to determine the intended type.
Environment data
Code Snippet
I made simple function which returns identity matrix like below
Repro Steps
just type the code
Expected behavior
obviously the function shouldn't have any problem, as code below returns no error at all
Actual behavior
pylance warn error like below
The text was updated successfully, but these errors were encountered: