mypy icon indicating copy to clipboard operation
mypy copied to clipboard

(🐞) Incorrect analysis of `while` loop subject

Open KotlinIsland opened this issue 1 year ago • 0 comments

class A:
    a: A | None

a: A | None
a = A()
while a := a.a:  # error: Item "None" of "A | None" has no attribute "a"  [union-attr]
    ...

When a becomes None, the while loop will not run, and a.a will not be evaluated

KotlinIsland avatar Feb 11 '24 23:02 KotlinIsland