importdataclassesfromenumimportEnumclassNodeStatus(Enum):
Offline=1Running=2Available=3@dataclasses.dataclassclassNode:
status: NodeStatus=NodeStatus.Offlinedefset_free(self) ->None:
self.status=NodeStatus.Availabledefprocess_node(node: Node) ->None:
ifnode.status!=NodeStatus.Offline:
return# This narrows node.status to Literal[NodeStatus.Offline] forevernode.set_free() # <<< mypy ignores side effects on .status from this# This should restore node.status to any Nodestatusifnode.status!=NodeStatus.Running: # error: Non-overlapping equality check (left operand type: "Literal[NodeStatus.Offline]", right operand type: "Literal[NodeStatus.Running]") [comparison-overlap]node.status=NodeStatus.Running
Expected Behavior
Reading node.status after calling node.set_free() should reset previous narrowing of node.status.
Actual Behavior
Narrowing done early inside a function can not be reset through mutating functions.
Activity