Strict equality not working between string and uuid
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 82
Description
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)
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Python reproducer with mypy 1.15.0, Python 3.12.9, --strict-equality, and --show-error-codes. Investigate why the string/uuid.UUID equality comparison is not reported while string/int is, then add or update coverage for this case. Done means the UUID comparison produces a comparison-overlap error without changing the existing string/int behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100