我在python中使用 mypytyping 模块 . 想象一下,我有一个泛型类型:

ContainerT = TypeVar('ContainerT')

class Thingy(Generic[ContainerT]):
    pass

但是我想在与TypeVar关联的具体类型中获取另一种类型,如下例所示:

class SomeContainer(object):
    Iterator = SomeCustomIterator

ContainerT = TypeVar('ContainerT')

class Thingy(Generic[ContainerT]):
    def foo(self) -> ContainerT.Iterator:
        pass

我收到一条错误消息,说 TypeVar 没有成员 Iterator . 是否有另一种方法可以重新制定这个,以便将一种类型与另一种类型联系起来

谢谢 .