-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongpriority-0-hightopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
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
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongpriority-0-hightopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder