Hello, I am writing a program like
T = TypeVar('T')
class A(Generic[T]):
def func(self, a: T, b: T.E):
pass
here I will only pass some special type as T
to class A
, which definitly own a class attribute E
which is also a type. Can I implement correctly in python? Obviously, the former code is wrong since T
is just a TypeVar, rather than type itself.
for example:
class X:
E = int
class Y:
E = float
these two type X
and Y
will be pass as T
to class A
.
If any one is familiar with c++, I just want to implement something like
template <typename T>
struct A {
void func(T a, typename T::E b);
};