mypy Type error for a class with an imported metaclass
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
Please provide more information to help us understand the issue:
- Are you reporting a bug, or opening a feature request? bug
- Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
Here is an example class I am working with.
@enum.unique
class MyEnumClass(Enum, metaclass=MyEnumMetaClass):
OUT_OF_STOCK = "Out of Stock"
LOW_STOCK = "Low Stock"
IN_STOCK = "In Stock"
EXCESS = "Excess"
I am making a change where I am importing the MyEnumMetaClass class from a PIP package now, whereas before it was located within the same project as this class.
- What is the actual behavior/output?
WithMyEnumMetaClassimported, whenever I create aMyEnumClassinstance, mypy gives me the following error:
error: The type "Type[MyEnumClass]" is not generic and not indexable - What is the behavior/output you expect?
I expect mypy to succeed here, given that the code is the same, it is just imported from a package now.
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 l’esempio minimo fornito di enum e metaclasse, verificandolo una volta con MyEnumMetaClass definito localmente e una volta quando viene importato da un pacchetto. Segui la differenza nella gestione della classe da parte di mypy e conferma che la versione importata non produca più l’errore segnalato secondo cui non è generica e non è indicizzabile.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- 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