Раскрытие typing.TypeVarTuple с "шаблонном"
Как мне получить тип tuple[A[int], A[int]]
для b.b
как в коде для c++?
import typing
T = typing.TypeVar('T')
Ts = typing.TypeVarTuple('Ts')
class A(typing.Generic[T]):
a: T
class B(typing.Generic[*Ts]):
b: tuple[*A[Ts]] # <<< Ошибка Pylance: TypeVarTuple not allowed in this context
b: B[int, int] = B()
typing.reveal_type(b.b) # выводит не правильный тип: tuple[A[*tuple[int, int]]]
# Ожидалось tuple[A[int], A[int]]
Код c++
#include <iostream>
#include <tuple>
#include <typeinfo>
template<typename T>
struct A {
T a;
};
template<typename... Ts>
struct B {
std::tuple<A<Ts>...> b;
};
int main() {
B<int, int> b;
std::cout << typeid(b.b).name() << std::endl;
// std::__1::tuple<A<int>, A<int>>
return 0;
}
Я пробовал tuple[*(A[T1] for T1 in Ts)]
, но Pylance игнорирует это и ругается вообще на квадратную скобку.
Источник: Stack Overflow на русском