python / python/mypy

mypy does not recognize tuple unpacking syntax for TypeVars.

Aperta
#11,655 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature priority-2-low topic-runtime-semantics topic-type-variables
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug Report

This is really a minor issue, but if you declare multiple TypeVar variables in one line, mypy does not seem to recognize them as type variables. For example,

from typing import TypeVar, Generic
T1, T2 = TypeVar('T1'), TypeVar('T2')

class Container(Generic[T1]):
    class Item(Generic[T2]):
        pass

To Reproduce

  1. Declare more than one TypeVars in one line. (See the example code above.)
  2. Run mypy check on this script.

Expected Behavior

The T1 and T2 in the example above should be recognized as type variables.
They should pass mypy check.

Actual Behavior

Errors:

$ mypy typevar.py 
typevar.py:5: error: Free type variable expected in Generic[...]
typevar.py:6: error: Free type variable expected in Generic[...]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10.0
  • Operating system and version: Ubuntu 20.04

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

Riproduci il problema con lo snippet Python fornito e il comando mypy typevar.py, quindi traccia il modo in cui vengono riconosciuti i TypeVars assegnati tramite tupla prima del controllo di Generic[...]. Il lavoro è completato quando sia T1 sia T2 vengono accettati come variabili di tipo e l’esempio supera mypy senza errori.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.