Mypy should report why each possible overload doesn't match
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature
Currently when no overload is valid for a function call mypy just lists the overloads with no explanation for why each one doesn't work:
No overload variant of "target" matches argument types "TargetType", "str", "ClobberConfig" [call-overload]
Possible overload variants:
def target(*, typ: TargetType, path: str | Path) -> Target[NoConfig]
def target(*, target_path: TargetPath) -> Target[NoConfig]
def [ConfigT <: Config] target(*, target_path: TargetPath, config: ConfigT) -> Target[ConfigT]
def [ConfigT <: Config] target(*, typ: TargetType, path: str | Path, config: ConfigT) -> Target[ConfigT]
Pitch
However, in this scenario I've manually verified that the last overload really should work. It's possible that it's a mypy bug, or it's possible that my reasoning is wrong, but if my reasoning is wrong it would be way more obvious if mypy told me why it's rejecting the overload I think should be accepted (the last one in this case). There's precedent too, C++ compilers nowadays do this for overloads and it greatly helps with understanding more complex (especially Generic) code.
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
Beginne damit, den Beispielaufruf mit Überladung zu reproduzieren, und untersuche die Diagnosen von mypy zur Überladungsauflösung. Verfolge, wo die Meldung "Possible overload variants" erzeugt wird; abgeschlossen ist die Aufgabe, wenn berichtet wird, warum jeder Kandidat abgelehnt wird, wobei das bestehende Verhalten beibehalten wird, wenn eine Überladung passt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100