Need plugin hooks for functions/methods
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
For some frameworks like pytest it would be useful to have a plugin that works with functions.
Currently mypy has decorator hook for classes.
Some ideas for possible hooks:
- update function namespace to inject some names
- modify function signature
- generate function signature (types)
For example pytest has the following fixture
from pathlib import Path
@pytest.fixture
def db_path(tmp_path: Path) -> Path:
return tmp_path / 'test.db'
The fixture is used by name:
def test_a(db_path) -> None:
....
db_path argument here is a calucated the result of db_path() fixture call.
It is bound by parameter name which is the same as the fixture name.
Adding a type to db_path argument is tedious, especially if a fixture returns some complex type like Callable[[str, int], Awaitable[web.Response]].
Technically all needed information can be extracted from fixture definition if the definition is type annotated.
A plugin for pytest would be awesome but as @ilevkivskyi said mypy needs a new hook to support it.
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 vorhandenen Decorator-Hook von mypy für Klassen und die in diesem Issue beschriebenen Konzepte der Plugin-API zu überprüfen. Ermittle, wie die Injektion in den Funktionsnamensraum, die Änderung von Signaturen und generierte Signaturen für pytest-style Fixtures funktionieren sollten, und definiere anschließend Tests, die zeigen, dass Fixture-Parameter den inferierten Rückgabetyp erhalten.
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
- Ruhig
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 35/100