Skip to content

False positive for "Non-overlapping identity check" when comparing EnumStr variants #19850

@jimbob88

Description

@jimbob88

Bug Report

The same issue as #10910 is occurring with enum.StrEnum in v1.18.1 even after #19422 .

To Reproduce

Gist URL: https://gist.github.com/mypy-play/2b3ca1612b3efc83cc712252610dfdf0
Playground URL: https://mypy-play.net/?mypy=master&python=3.13&flags=strict&gist=2b3ca1612b3efc83cc712252610dfdf0

import enum
from dataclasses import dataclass


class Status(enum.StrEnum):
    ALIVE = "alive"
    KILLED = "killed"
    STALE = "stale"
    REJECTED = "rejected"


@dataclass
class SomeThing:
    status: Status


def status_updater(some_thing: SomeThing) -> None:
    some_thing.status = Status.KILLED


the_thing = SomeThing(status=Status.ALIVE)

assert the_thing.status == Status.ALIVE

status_updater(the_thing)

assert the_thing.status == Status.KILLED

Expected Behavior

When running with mypy --strict, this should not result in an error because the status could change in the status_updater. This would make StrEnum work like Enum

Actual Behavior

main.py:27: error: Non-overlapping equality check (left operand type: "Literal[Status.ALIVE]", right operand type: "Literal[Status.KILLED]")  [comparison-overlap]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.18.1 (compiled: yes)
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: Python 3.13.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-overlapOverlapping equality check

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions