I’m attempting to inherit from a Generic class with variadic keyword arguments in Python 3.10
from typing_extensions import Unpack, TypeVar, ParamSpec
P = ParamSpec("P")
T = TypeVar("T")
class A(Generic[P]):
def func(self, *args: P.args, **kwargs: P.kwargs):
print(args)
print(kwargs)
return 2
class Inputs(TypedDict):
arg1: int
arg2: str
class B(A[Unpack(Inputs)]): # Line where mypy fails
pass
B().func(arg1=1, arg2="Hello")
However, mypy (1.10.0) fails this check with the following. Is there another way to implement this functionality? I’ve seen it be used in Callables, but I prefer to not approach it that way
error: Unpack is only valid in a variadic position
New contributor
Ant Ants Ant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.