Add reference implementation of PEP 718
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia leggendo i controlli collegati in mypy/checkexpr.py intorno alle righe 4948-4949 e l’helper in mypy/semanal.py intorno alla riga 8235, quindi confrontali con PEP 718 e con l’infrastruttura TypeForm esistente. Il lavoro sarà completato quando il progetto avrà un’implementazione di riferimento concordata e i relativi casi supportati di applicazione dei tipi e il comportamento in base alla versione di Python saranno coperti dai test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Attiva
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 35/100