Add reference implementation of PEP 718
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
I think this is very much needed PEP, and using mypy for reference implementation is a good idea because mypy actually already (mostly) supports this under the hood.
The only non-trivial question is whether we should allow type applications only to references that are statically known to refer to a function, or do we want to support type application to an arbitrary expression that happen to have a callable-like type inferred? For example:
T = TypeVar("T")
class Callbacks(TypedDict):
regular: Callable[[int], int]
generic: Callable[[T], T]
def test(cb: Callbacks) -> None:
cb["generic"][int] # <- should we support this?
If we only want to support static references, then implementation is trivial, essentially:
- Make this error conditional on Python version <3.15 and file being not a stub.
- Update this helper to accept a
Decorator.
However, if we want to support arbitrary expressions, it should be quite easy as well. Luckily, all the necessary infrastructure was added for TypeForm PEP support. We can use TypeCheckerAsSemanticAnalyzer adapter to re-interpret arbitrary expression as type during type checking.
cc @JukkaL @Gobot1234 @PabloRuizCuevas
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, die verlinkten Prüfungen in mypy/checkexpr.py ungefähr bei den Zeilen 4948–4949 und den Helper in mypy/semanal.py ungefähr bei Zeile 8235 zu lesen, und vergleiche sie anschließend mit PEP 718 und der bestehenden TypeForm-Infrastruktur. Die Arbeit ist abgeschlossen, wenn das Projekt eine vereinbarte Referenzimplementierung hat und ihre unterstützten Typanwendungsfälle sowie das Verhalten für verschiedene Python-Versionen durch Tests abgedeckt sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Aktiv
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 35/100