python / python/mypy

Plugins and overloads don't interact well

Offen
#7,367 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug needs discussion priority-0-high topic-overloads topic-plugins
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

While working on our own plugin for self-checking proper types and isinstance() I have tried to use get_function_hook() to emit some additional errors for overloaded functions. However this didn't work for three reasons:

  • The hook is called for every item in the overload, not for the overload as a whole.
  • The overload logic relies on empty Messages as a sign of successful match
  • The errors emitted during overload selection are discarded afterwards, thus discarding the plugin generated errors

This issue can be fixed in three ways:

  • Calling the hook on the overload as a whole after selecting the overload variant and type checking it (this however will be a breaking API change)
  • Use newly added error codes to only abandon a variant if the error is due to bad argument type (this is however still bad because check_call() may have an accept() call possibly triggering almost arbitrary error including a nested function call with bad argument type).
  • Use a boolean attribute somewhere that will be set by check_argument_types() and will be reset after return from every accept().

I am leaning towards the last option, since it is most principled IMO.

cc @Michael0x2a

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, get_function_hook() über die Auswahl von Überladungen, check_call(), check_argument_types() und accept() hinweg zu verfolgen. Vergleiche, wie die Überladungsübereinstimmung leere Messages verwendet und wie Plugin-Fehler verworfen werden. Abgeschlossen ist die Aufgabe, wenn von Plugins erzeugte Fehler die Auswahl von Überladungen überstehen, ohne gültige Überladungsvarianten fälschlicherweise abzulehnen, und das ausgewählte Verhalten konsistent bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
compilers, devtools
Issue-Typ
Bug
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.