dmypy suggest generates syntax error in annotation in some cases
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
sometimes dmypy puts a : for some annotations instead of a . and is inconsistent with some types from typing
To Reproduce
class C: pass
def f1():
return [C()]
def f2():
return [1]
def f3():
return (C(),)
def f4():
return (1,)
[mypy]
check_untyped_defs = true
Expected Behavior
$ dmypy run .
...
$ dmypy suggest t.f1
() -> List[t.C]
$ dmypy suggest t.f2
() -> List[int]
$ dmypy suggest t.f3
() -> Tuple[t.C]
$ dmypy suggest t.f4
() -> Tuple[int]
Actual Behavior
$ dmypy run .
...
$ dmypy suggest t.f1
() -> typing:List[t.C]
$ dmypy suggest t.f2
() -> typing.List[int]
$ dmypy suggest t.f3
() -> Tuple[t.C]
$ dmypy suggest t.f4
() -> Tuple[int]
two separate oddities here:
- the first produces
typing:List(with a colon) instead oftyping.List(the colon appears to come from here -- https://github.com/python/mypy/blob/454989f7c085d5a7f86ad7ed9da0f2614ca41d83/mypy/suggestions.py#L853 )- I guess the colon is supposed to help with differentiating
mod.Class.NestedClassvsmod.submod.Class? though it seems to make no sense forListhere
- I guess the colon is supposed to help with differentiating
typing.ListandTupleshould either both be fully qualified or neither
Your Environment
- Mypy version used: 1.15.0
- Mypy command-line flags: see above
- Mypy configuration options from
mypy.ini(and other config files): see above - Python version used: 3.13.1
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
Reproduziere das Problem mit den gezeigten dmypy suggest-Beispielen und untersuche anschließend mypy/suggestions.py in der Nähe von Zeile 853, um nachzuverfolgen, wie die Namen von Annotationen formatiert werden. Erledigt ist die Aufgabe, wenn die List- und Tuple-Ausgaben eine konsistente Qualifizierung verwenden und keine Annotation den fehlerhaften Doppelpunkt enthält; überprüfe dies anhand aller vier Beispiele.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 50/100