Type variable across types gives an error when using Generics
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report
When using a TypeVar defined in another local file, to parameterize a Generic, the following error is given:
Free type variable expected in Generic[...]
To Reproduce
Create file value.py:
from typing import TypeVar, Protocol
TValue = TypeVar('TValue', covariant=True)
# As an example, this does not give me any errors
class IValueProcessor(Protocol, Generic[TValue]):
...
Create service.py:
from abc import ABC
from typing import Generic
from .value import TValue
class Service(ABC, Generic[TValue]): # Error occurs here, on `Generic`
...
Expected Behavior
Should not give any errors (I think).
Actual Behavior
An error is produced, when parameterizing Generic:
Free type variable expected in Generic[...]
Your Environment
- Mypy version used: 0.930
- Mypy command-line flags: (none)
- Mypy configuration options from
mypy.ini(and other config files): (none was created, at least explicitly) - Python version used: CPython 3.8.10
- Operating system and version: Ubuntu 20.04 LTS on WSL2
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 con la riproduzione nei due file value.py e service.py, quindi esegui mypy 0.930 senza configurazione né flag da riga di comando per confermare l’errore. Traccia come viene gestito il TValue importato durante l’elaborazione di Generic[TValue] e aggiungi un test di regressione basato su questo esempio; il lavoro è terminato quando la dichiarazione generica valida non segnala più “Free type variable expected in Generic[...]”.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers, devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100