Generic Paramspec How to Specify Subclass Concrete #1125
-
For normal TypeVars you can have a subclass of a generic type specify variable like,' T = TypeVar('T')
class Container(Generic[T]):
...
class IntContainer(Container[int]):
... How do you do that for classes generic over paramspec? P = Paramspec('P')
class Func(Generic[P]):
...
class SimpleFunc(Func[XYZ]):
... What can I do to fill in XYZ? In this case I just want SimpleFunc to have Paramspec corresponding to an empty argument list as while Func is generic over P, SimpleFunc is not. I can make a more complete example. The motivation is describing type of apache beam's process classes. That library is used to describe batch computations and the api is base classes are pretty generic including part of argument signature (paramspec), but most user subclasses will have a concrete description of P. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Looking over PEP 612 again looks like there is a section on this here about user defined generics and that list of types just works. So I can just do Func[[]] or Func[[int, bool]]. |
Beta Was this translation helpful? Give feedback.
Looking over PEP 612 again looks like there is a section on this here about user defined generics and that list of types just works. So I can just do Func[[]] or Func[[int, bool]].