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
The type of items in a list is not inferred when using an isinstance check in an all call.
from typing import List
class A:
pass
class B(A):
pass
def test(arg: List[A]) -> None:
if all([isinstance(a, B) for a in arg]):
test2(arg)
def test2(arg: List[B]) -> None:
pass
What is the actual behavior/output?
error: Argument 1 to "test_2" has incompatible type "List[A]"; expected "List[B]"
Found 1 error in 1 file (checked 1 source file)
What is the behavior/output you expect?
I expect mypy to infer the type of the list items based on the if check.
What are the versions of mypy and Python you are using?
mypy: v0.740
python: 3.6.7
The text was updated successfully, but these errors were encountered:
This is a feature request; mypy currently only understands a very small number of special type-narrowing functions (like isinstance()). I don't think there are plans to add more, but contributions would likely be accepted.
Uh oh!
There was an error while loading. Please reload this page.
The type of items in a list is not inferred when using an
isinstance
check in anall
call.I expect mypy to infer the type of the list items based on the if check.
mypy: v0.740
python: 3.6.7
The text was updated successfully, but these errors were encountered: