# Type annotations with dependent name

**URL:** <https://discuss.python.org/t/type-annotations-with-dependent-name/11423>\
**Category:** Python Help\
**Tags:** typing\
**Created:** [October 23, 2021, 11:39pm UTC](https://discuss.python.org/t/type-annotations-with-dependent-name/11423 "2021-10-23T23:39:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hzhangxyz](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/hzhangxyz/32/3083_2.png) [@hzhangxyz](https://discuss.python.org/u/hzhangxyz)\
**Post date:** [October 23, 2021, 11:39pm UTC](https://discuss.python.org/t/type-annotations-with-dependent-name/11423/1 "2021-10-23T23:39:58Z")

</div>

Hello, I am writing a program like

```auto
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:

```auto
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

```auto
template <typename T>
struct A {
  void func(T a, typename T::E b);
};

```

---

<div class="post-metadata">

**Author:** ![hzhangxyz](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/hzhangxyz/32/3083_2.png) [@hzhangxyz](https://discuss.python.org/u/hzhangxyz)\
**Post date:** [October 24, 2021, 12:49am UTC](https://discuss.python.org/t/type-annotations-with-dependent-name/11423/2 "2021-10-24T00:49:29Z")

</div>

I try to pass generic argument to A. **init**

```auto
class A:
  def __init__ (self, T):
    self.T = T
  def func(self, a: self.T, b: self.T.E):
    pass

```

but this seems an invalid annotations
