"Can only assign concrete classes to a variable of type "Type[MyProtocol]"" is hard to debug
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Riproduci l'esempio in main.py con mypy 0.770 o master, quindi segui la diagnostica che segnala "Can only assign concrete classes to a variable of type Type[MyProtocol]." Il lavoro è completato quando l'errore spiega perché MyImplementation non è concreta, inclusa la definizione del nome mancante descritta nell'issue.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
If you consider bad error messages a bug, it is a bug. Otherwise, it is a feature request.
The following code sample is wrong because name is not optional. Defining name's value in MyImplementation or its constructor would fix this code.
from typing import Type, Protocol
class MyProtocol(Protocol):
name: str
class MyImplementation(MyProtocol):
pass
foo: Type[MyProtocol] = MyImplementation
However, running mypy from master or 0.770 produces an error which is very challenging to debug:
main.py:9: error: Can only assign concrete classes to a variable of type "Type[MyProtocol]"
Ideally, mypy would tell me the underlying problem. In this case, I took nearly a whole day of experimenting to fix it, ultimately needing to delete code until I got the error message to change. It would be ideal if mypy could say "and it is not concrete because name is not defined statically or in __init__." or something.
-
What are the versions of mypy and Python you are using?
mypy 0.770, python 3.8, yes it persists on master -
What are the mypy flags you are using? (For example --strict-optional)
This behavior seems unchanged by flags.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Merge medio
- 1g 18h
- PR unite (30g)
- 54
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.
Altre issue di python/mypy
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug topic-configuration topic-error-reporting
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Issue simili
-
link-check link-check:sphinx-theme
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
OpenHands/extensions#626 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
CSCfi/sd-search-api#39 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100