我正在尝试向现有包添加类型注释,显然我错过了一些重要的东西。我有一个抽象的超类和子类。超类应该是通用的,而子类应该是针对特定类型的。这是我看到的一个简单示例,以及我希望看到的内容:
from typing import Generic, TypeVar
T = TypeVar("T")
class A(Generic[T]):
def method(self, arg: T):
...
class B(A[int]):
def method(self, arg):
reveal_locals()
Run Code Online (Sandbox Code Playgroud)
预期(或至少希望):
GenericTest.py:11: note: Revealed local types are:
GenericTest.py:11: note: arg: int
GenericTest.py:11: note: self: Any
Run Code Online (Sandbox Code Playgroud)
得到了:
GenericTest.py:11: note: Revealed local types are:
GenericTest.py:11: note: arg: Any
GenericTest.py:11: note: self: Any
Run Code Online (Sandbox Code Playgroud)