Hi David, thanks for your response!
It is very similar. The crux of the problem is that in the example the same type parameter is used for the initializer parameter, the object attribute, and the method return type (Tuple[*Shape]). In my case, the type of the initializer parameter is different from (but related to) the method return type, because I am initializing with classes but returning values (instances of the classes that were passed to the initializer.)
A non-generic (type parameters replaced with concrete types) version of what I’m trying to do would look something like this:
class TupleOf:
member_types: tuple[type[int], type[str], type[bool]]
def __init__(self, types: tuple[type[int], type[str], type[bool]]):
self.member_types = types
def get_values(self, tokens: list[str]) -> tuple[int, str, bool]:
values = []
for cls in self.member_types:
raw = tokens.pop(0)
values.append(cls(raw))
return tuple(values)
I don’t think there is a way to “map” the Type special form over the contents of a TypeVarTuple, so that one can annotate both the type of a value ad the type itself like with TypeVar and Type[T].