Strict equality not working between string and uuid
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 5.1k
- Fork
- 2.1k
- Merge medio
- 1g 19h
- PR unite (30g)
- 82
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo il riproduttore Python fornito con mypy 1.15.0, Python 3.12.9, --strict-equality e --show-error-codes. Indaga sul motivo per cui il confronto di uguaglianza string/uuid.UUID non viene segnalato mentre viene segnalato string/int, quindi aggiungi o aggiorna la coverage per questo caso. Il lavoro è completato quando il confronto UUID produce un errore comparison-overlap senza modificare il comportamento esistente di string/int.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100