FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

`comparision-overlap` ignores side-effects from member function calls · Issue #19783 · python/mypy · GitHub

Repository navigation

comparision-overlap ignores side-effects from member function calls #19783

Closed as duplicate

Description

To Reproduce
mypy --strict on file below gives following false error:

scratch_43.py:20:8: error: Non-overlapping equality check (left operand type: "Literal[NodeStatus.Offline]", right operand type: "Literal[NodeStatus.Running]")  [comparison-overlap]
import dataclasses
from enum import Enum

class NodeStatus(Enum):
    Offline = 1
    Running = 2
    Available = 3

@dataclasses.dataclass
class Node:
    status: NodeStatus = NodeStatus.Offline

    def set_free(self) -> None:
        self.status = NodeStatus.Available

def process_node(node: Node) -> None:
    if node.status != NodeStatus.Offline:
        return                                  # This narrows node.status to Literal[NodeStatus.Offline] forever

    node.set_free()                             # <<< mypy ignores side effects on .status from this
                                                #     This should restore node.status to any Nodestatus
    if node.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.

Your Environment

  • Mypy version used: 1.17, 1.14, 1.13
  • Mypy command-line flags: --strict
  • Python version used: 1.13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL