You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to express a callable type with keyword arguments, you can use a call protocol, but this doesn't work for other classes that are generic in ParamSpec. For example, in pytorch, network layers have to inherit from Module which should be typed approximately like this (using Python 3.12 generic syntax):
classModule[T, **P]:
@abstractmethoddefforward(self, *args: P.args, **kwargs: P.kwargs) ->T: ...
def__call__(self, *args: P.args, **kwargs: P.kwargs) ->T:
# do other stuffreturnself.forward(*args, **kwargs)
But what to do if I want to override forward with an optional argument?
Feature
Related to
TypedDict unpacking in ParamSpec would work just like it works now in Callables.
Pitch
In order to express a callable type with keyword arguments, you can use a call protocol, but this doesn't work for other classes that are generic in
ParamSpec
. For example, in pytorch, network layers have to inherit fromModule
which should be typed approximately like this (using Python 3.12 generic syntax):But what to do if I want to override
forward
with an optional argument?With TypedDict unpacking in ParamSpec:
The text was updated successfully, but these errors were encountered: