Closed
Description
Mypy doesn't seem to handle variable type changes that happen with a walrus operator.
What happens here is: the walrus operator makes it a boolean:
while i:= update(i) > 0
.
This is what needs to happen to check for i > 0
and i
still being an int.
while (i:= update(i)) > 0
.
The following python code doesn't give any errors with mypy 0.750:
def walrus1(i: int) -> int:
"""Actually returns bool"""
while i:= i > 0:
return i
return i
def walrus2(i: int) -> int:
"""Works correctly."""
while (i:= i) > 0:
return i
return i
assert walrus1(5) == True
assert walrus1(0) == False
assert walrus2(5) == 5
assert walrus2(0) == 0
Metadata
Metadata
Assignees
Labels
No labels