Making functions/methods subscriptable
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 302
- Merge medio
- 23h
- PR unite (30g)
- 8
Descrizione
I'd like to make both instances and the types of functions and methods (including builtin methods) subscriptable.
Part of this proposal has been discussed already on python-ideas (https://discuss.python.org/t/making-functions-subscriptable-at-runtime/26463) but I thought it might also be worthwhile making FunctionType etc. subscriptable and work in a similar way to Callable just with extra descriptor behaviour that binds it into a MethodType.
class Foo:
bar: FunctionType[[Self, int], str]
# equivalent to
def bar(self, arg1, /) -> str: ...
This is different from Callable as if FunctionType was replaced with Callable, bar would always require a self argument.
This unfortunately probably requires special casing in type checkers as it isn't quite currently possible with PEP 612 (ParamSpec + Concatenate) (see #946) unless the PEP is updated
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
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 la discussione collegata di python-ideas, poi esamina PEP 612 e issue #946 per comprendere i limiti indicati. La proposta coinvolge un FunctionType subscriptable e tipi correlati, il binding dei descriptor e probabilmente casi speciali nel type-checker; per considerarla completata sarebbero necessari un design concordato e il relativo supporto del type-checker.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- developer-experience
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100