以下代码无法使用 PyType 进行类型检查:
def Thing:
_things = [] # type: List['Thing']
@classmethod
def get(cls, id_: int) -> Container['Thing']:
return Container(cls._things[id_])
出现以下错误get
:
Invalid instantiation of generic class [bad-concrete-type]
Expected: Any
Actually passed: Any
我在https://gist.github.com/brunokim/e86367ed63cbd52d96b3564f502831b2添加了一个完整的 MWE 。我是否缺少正确注释类属性的内容things
?我注意到 pyi 文件与实例属性没有什么不同。