Closed
Description
# mypy: enable-error-code=redundant-expr
from __future__ import annotations
class Node:
parent: Node | None
is_valid: bool
def traverse_needs_fixing(self) -> Node | None:
it: Node | None
it = self
while it is not None and it.is_valid: # E: Left operand of "and" is always true [redundant-expr]
it = it.parent
return it
def traverse(self) -> Node | None:
# this only works because mypy does not narrow on initial assignment
# which is something we'd like to change, see #2008
it: Node | None = self
while it is not None and it.is_valid:
it = it.parent
return it