python / python/mypy

Assigning an iterator to the type hint `collections.abc.Hashable` gets error even though an iterator is hashable

Aperta
#20,236 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

*Memo:

  • Python 3.14.0
  • mypy 1.18.2
  • mypy test.py
  • Windows 11

An iterator is hashable as shown below:

print(hash(iter([0, 1, 2])))
# 127553071047

But assigning an iterator to the type hint collections.abc.Hashable gets the error as shown below even though an iterator is hashable:

from collections.abc import Hashable

v: Hashable = iter([0, 1, 2])
# Error

error: Incompatible types in assignment (expression has type "Iterator[int]", variable has type "Hashable")

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo l'assegnazione in test.py con Python 3.14.0 e mypy 1.18.2, quindi traccia il modo in cui mypy modella Iterator[int] e collections.abc.Hashable. Il lavoro è completato quando la discrepanza segnalata è stata risolta oppure il suo comportamento statico previsto è stato stabilito con un test di regressione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.