Skip to content

Strict equality not working between string and uuid #13632

Open
@sk-

Description

@sk-

Bug Report

--strict-equality seems to only work in very reduced cases. In particular, it is not working when comparing strings and uuids.

To Reproduce

import uuid
from typing import TYPE_CHECKING, reveal_type

a = uuid.uuid4()
b = str(a)

if TYPE_CHECKING:
  reveal_type(a)
  reveal_type(b)
print(a == b)

c = "c"
d = 500
print(c == d)

https://mypy-play.net/?mypy=latest&python=3.12&flags=show-error-codes%2Cstrict-equality&gist=6c8273316b52930967ad0f8062c57aa3

Expected Behavior

The comparison in line 10 should raise a comparison overlap error. Something like

test_strict_equality.py:10: error: Non-overlapping equality check (left operand type: "str", right operand type: "uuid.UUID")  [comparison-overlap]

Actual Behavior

Mypy does not flag the string/UUID comparison as incompatible

test_strict_equality.py:8: note: Revealed type is "uuid.UUID"
test_strict_equality.py:9: note: Revealed type is "builtins.str"
test_strict_equality.py:14: error: Non-overlapping equality check (left operand type: "str", right operand type: "int")  [comparison-overlap]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags: --strict-equality --show-error-codes
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.12.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions