python / python/mypy

mypy rejects unpacking into same variable

Aperta
#14,786 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Bug Report

I believe the following code should be fine, however mypy rejects the case where we're unpacking into the variable which was expanded:

foo: tuple[int, ...] = ()

# Ok
bar, *quox = foo

# Incompatible types in assignment (expression has type "List[int]", variable has type "Tuple[int, ...]")  [assignment]
bar, *foo = foo

There are a number of similar issues reported, the closest being https://github.com/python/mypy/issues/9706, however I believe this is distinct as it reproduces when the generic type is int (though my original code was using str). This suggests a different root cause.

Your Environment

  • Mypy version used: 1.0.1
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10

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 eseguendo lo snippet Python 3.10 riportato con mypy 1.0.1 e tracciando come viene verificata l’assegnazione con unpacking quando la variabile sottoposta a unpacking è anche la sorgente. Aggiungi un test di regressione per questo caso, assicurandoti che l’unpacking della stessa variabile venga accettato mentre le assegnazioni incompatibili continuino a essere diagnosticate.

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

Valutazione

Stack tecnologico
python
Ambito
compilers
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.