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
I believe the example below depicts a bug in mypy's handling of isinstance. According to the documentation, isinstance informs the type of the variable inside the if block - but the following example shows that this is not the case:
$ pip freeze | grep mypy
mypy-lang==0.4.2
$ cat -n bug.py
1 class A:
2 pass
3
4 class B(A):
5 def __init__(self):
6 self._members = [1]
7
8 class C(A):
9 def __init__(self):
10 self._members = [2]
11
12 class D(A):
13 pass
14
15 def foo(a: A) -> bool:
16 if isinstance(a, B) or isinstance(a, C):
17 for m in a._members:
18 print(m)
19
20 foo(B())
21 foo(C())
$ mypy bug.py
bug.py: note: In function "foo":
bug.py:17: error: "A" has no attribute "_members"
In line 17, the a variable is of type B or C - so it does have access to _members.
The text was updated successfully, but these errors were encountered:
I believe the example below depicts a bug in mypy's handling of
isinstance
. According to the documentation,isinstance
informs the type of the variable inside theif
block - but the following example shows that this is not the case:In line 17, the a variable is of type B or C - so it does have access to
_members
.The text was updated successfully, but these errors were encountered: