Generic ParamSpec in subclass definitions
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 302
- Merge medio
- 23h
- PR unite (30g)
- 8
Descrizione
Given some base class that is generic over a param-spec, I'd like to be able to define the param-spec using a subclass method implementation. Something like:
T = TypeVar("T")
P = ParamSpec("P")
class Base(Generic[P, T]):
func: Callable[P, T]
# for instance
def wrapper(self, *args: P.args, **kwargs: P.kwargs) -> Tuple[T]:
return (self.func(*args, **kwargs), )
class Subclass(Base):
def func(self, x: int, *, y: str) -> bytes: ...
That is, the base class is generic over some function definition, and the subclass implement that function as a method. I'm not sure how common this pattern is, but I see it a fair amount when the class gets more complicated and you can't just use a decorator (e.g. torch.nn.Module.forward is a big example of this). Is there some other way of specifying "infer the parameters from this method implementation"? Is this something that would require an update to the specification, is it "just" a feature request to the method implementation "like" an assignment statement?
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
Non viene indicato alcun file, test o punto di ingresso dell'implementazione. Inizia esaminando l'esempio dell'issue relativo a ParamSpec, Generic e al metodo della sottoclasse insieme alla specifica del typing di Python; determina se l'inferenza richiesta è supportata o richiede una modifica della specifica. Il lavoro è completato quando il comportamento e l'ambito della sua implementazione sono stati decisi esplicitamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100