python / python/mypy

Plugin API feature requests

Offen
#5,409 4 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature priority-1-normal topic-plugins
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

I recently wrote a plugin that used get_function_hook() to intercept instantiations of a certain set of classes (recognized by name), and found a bunch of functionality missing. Here's a list.

  • I needed the names of the arguments but they were not directly available. I ended up using rtype.type.names['__init__'].node.arg_names (with various type and None guards) and subtracting 1 to compensate for self, which looked very hacky. It would be nice if FunctionContext also has an arg_names argument.

  • CheckerPluginInterface has no fail() method. It exists on the implementation, and the similar TypeAnalyzerPluginInterface does define it.

  • I needed to look up a name in the module's global namespace; I ended up calling ctx.api.lookup_qualified() but that's not in the interface, and perhaps it's not the thing to use.

  • I needed the functionality of parse_bool() but it's not there (it only exists on SemanticAnalyzerPluginInterface).

  • I needed something similar to what's in mypy/plugins/common.py as _get_bool_argument() _get_argument() but had to write my own because the starting point was a FunctionContext instead of a ClassDefContext.

  • (Not directly a plugin issue, but this happened.) I was also bitten by the error message The type alias{} is invalid in runtime context -- this seems a bit inconsistent because expanding the Union that the alias references makes it go away. I.e. if A = Optional[int], foo(A) gives that error, but foo(Optional[int]) doesn't.

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

Überprüfe die Plugin-Schnittstellen rund um FunctionContext, CheckerPluginInterface und SemanticAnalyzerPluginInterface sowie mypy/plugins/common.py und das gemeldete Laufzeitverhalten von Typaliasen. Das Issue enthält mehrere separate API-Anfragen statt einer einzigen abgegrenzten Änderung; für den Abschluss müsste entschieden werden, welche Anfragen unterstützt werden, und ihr erwartetes Verhalten müsste definiert werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

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