"Can only assign concrete classes to a variable of type "Type[MyProtocol]"" is hard to debug
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Reproduziere das Beispiel in main.py mit mypy 0.770 oder master und verfolge dann die Diagnose, die "Can only assign concrete classes to a variable of type Type[MyProtocol]." meldet. Als erledigt gilt die Aufgabe, wenn der Fehler erklärt, warum MyImplementation nicht konkret ist, einschließlich der in der Issue beschriebenen fehlenden Namensdefinition.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- Ø Merge
- 1 T. 18 Std.
- Gemergte PRs (30 T.)
- 54
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/mypy
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
bug topic-configuration topic-error-reporting
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
bancolombia/sentinel#23 ·
-
test md OffenCI
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100