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
If you try to assign or return a list of a more specific type, mypy prints a helpful note warning that "List" is invariant, and suggests you use the "Sequence" type instead.
If you have a child class override a method to modify its return type to a list of a more specific type, mypy tells you the return type is incompatible but doesn't let you know that switching to the "Sequence" type might resolve their error.
main.py:3: error: Incompatible types in assignment (expression has type "List[int]", variable has type "List[float]")
main.py:3: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
main.py:3: note: Consider using "Sequence" instead, which is covariant
main.py:6: error: Incompatible return value type (got "List[int]", expected "List[float]")
main.py:6: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
main.py:6: note: Consider using "Sequence" instead, which is covariant
main.py:13: error: Return type "List[int]" of "get_numbers" incompatible with return type "List[float]" in supertype "Parent"
main.py:13: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
main.py:13: note: Consider using "Sequence" instead, which is covariant
Found 3 errors in 1 file (checked 1 source file)
Actual Behavior
main.py:3: error: Incompatible types in assignment (expression has type "List[int]", variable has type "List[float]")
main.py:3: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
main.py:3: note: Consider using "Sequence" instead, which is covariant
main.py:6: error: Incompatible return value type (got "List[int]", expected "List[float]")
main.py:6: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
main.py:6: note: Consider using "Sequence" instead, which is covariant
main.py:13: error: Return type "List[int]" of "get_numbers" incompatible with return type "List[float]" in supertype "Parent"
Found 3 errors in 1 file (checked 1 source file)
Your Environment
Mypy version used: 0.971
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.10.6
The text was updated successfully, but these errors were encountered:
If you try to assign or return a list of a more specific type, mypy prints a helpful note warning that "List" is invariant, and suggests you use the "Sequence" type instead.
If you have a child class override a method to modify its return type to a list of a more specific type, mypy tells you the return type is incompatible but doesn't let you know that switching to the "Sequence" type might resolve their error.
To Reproduce
https://gist.github.com/1c07da0019991a5f14b9ff3a84e393db
Expected Behavior
The invariant note is included for all 3 errors
Actual Behavior
Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: