python / python/mypy

type inference failure on custom iterable class unpacking

Aperta
#20,435 2 commenti 2 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

Bug Report

When unpacking a custom iterable class to build another iterable, mypy does not correctly infer the resulting type i.e. CustomIter[CustomIter[_T]] is equal to CustomIter[_T] (that should not be true)

To Reproduce

proof-of-concept

Expected Behavior

Nested iterable unpacking type checking works fine when using standard types (e.g. list[list[_T]]) however custom iterable classes should have the same behavior.

Actual Behavior

As presented on the playground proof-of-concept the issue is that mypy does not mark the failure on this incorrectly defined function:

def case_1(iter_of_iter: CustomIter[list[int]]) -> CustomIter[int]:
    # Mypy fails
    #
    # Mypy does not flag that the return type does not match.
    # It is `CustomIter[list[int]]` instead of `CustomIter[int]`
    return CustomIter.new(*iter_of_iter)

Your Environment

  • details available on the playground example.

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 con la prova di concetto mypy-play collegata e riproduci il fallimento con i flag strict indicati. Traccia come viene inferito l'unpacking di un CustomIter[CustomIter[_T]], quindi verifica che il caso errato venga rifiutato, mentre gli iterable standard annidati mantengono il loro comportamento esistente.

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
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.