-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-1-normal
Description
Mypy forgets type information after a nested if-statement. Small example:
class Base:
pass
class B(Base):
def __init__(self):
self.args = []
class C(Base):
def __init__(self):
self.args = []
def check(x: Base):
if isinstance(x, (B, C)):
print(x.args) # No error here.
if isinstance(x, B):
print("B")
elif isinstance(x, C):
print("C")
print(x.args) # error: "Base" has no attribute "args"
Mypy 0.620 correctly infers that x has a member args for the first print statement, but after the nested if statement, it has forgotten about that and throws an error.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-1-normal