Error message for `TypeForm` arguments with a single unresolvable forward reference is misleading
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
When passing a single strategized type expression to a function accepting a TypeForm argument, which cannot be fully resolved, due to e.g. a missing import, we get an arg-type error of the form:
Instead of an error, telling us why the type expression is invalid.
To Reproduce
https://mypy-play.net/?mypy=master&python=3.14&gist=891447236311046360886ba63c1fac83
from typing_extensions import TypeForm
def foo[T](x: TypeForm[T]) -> None:
pass
foo("Unresolvable")
Expected Behavior
mypy should emit a name-error for Unresolvable, since it was never defined. The given example is probably the most controversial case though, since someone may actually accidentally be passing an invalid string literal, but the same thing happens for less controversial cases like "list[Unresolvable]". But I think either way it makes more sense to treat the given string literal as a type expression and emit the same errors you would emit if you saw the same string literal in an annotation.
Actual Behavior
error: Argument 1 to "foo" has incompatible type "str"; expected "TypeForm[Never]" [arg-type]
This error does not help us solve the problem in our code at all.
Your Environment
- Mypy version used: 2.2
- Python version used: 3.14
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Führe zunächst die bereitgestellte mypy-play-Reproduktion mit mypy 2.2 und Python 3.14 aus und verfolge dann den TypeForm-Argumentprüfpfad für einen einzelnen nicht auflösbaren String-Ausdruck. Abgeschlossen ist die Aufgabe, wenn das Beispiel einen name-error für Unresolvable meldet, statt nur den irreführenden arg-type-Fehler.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 52/100