Generate better error message for incompatible **kwargs
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
This output is from #8772:
$ mypy test.py
test.py:6: error: Argument 2 to "dumps" has incompatible type "**Dict[str, int]"; expected "bool"
test.py:6: error: Argument 2 to "dumps" has incompatible type "**Dict[str, int]"; expected "Optional[Type[JSONEncoder]]"
test.py:6: error: Argument 2 to "dumps" has incompatible type "**Dict[str, int]"; expected "Optional[Tuple[str, str]]"
test.py:6: error: Argument 2 to "dumps" has incompatible type "**Dict[str, int]"; expected "Optional[Callable[[Any], Any]]"
Found 4 errors in 1 file (checked 1 source file)
The error messages are pretty confusing. We should special case this and produce a customized error message that explains the situation better.
Here's the code that triggers the errors:
import json
json_kwargs = dict(indent=2)
json.dumps({}, **json_kwargs)
Some ideas about what to do:
- Generate a single error message instead of multiple ones.
- Add a note suggesting the use of
Dict[str, Any]or a TypedDict type for the**kwargsargument. - Maybe also explain that mypy matches the value type against all arguments, or add a link to documentation (add something to common issues, for example).
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, das Beispiel in test.py mit json.dumps nachzustellen und es mit der Ausgabe aus #8772 zu vergleichen. Verfolge anschließend die bestehende **kwargs-Fehlerberichterstattung und mache das Ergebnis zu einer einzigen klaren Diagnose mit Hinweisen zu Dict[str, Any] oder TypedDict; überprüfe, dass die verwirrenden wiederholten Fehler verschwunden sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100