from typing import TypeVar, Generic, Sequence
T = TypeVar("T")
class A(Generic[T]):
pass
class B(A[Sequence[T]], Generic[T]):
pass
b: B[int] = B()
reveal_type(b)
如预期的那样B[int]
。有没有办法让reveal_type
告诉我A[Sequence[int]]
在这个简单的例子中,这是没有用的,但是在这个例子中,我正在调试如何在给定参数化子类型的情况下参数化超类型,而不必手动连接点(并且可能与mypy
的推断相矛盾),这将使事情变得更清楚
您可以编写一个助手:
在mypy操场上,这显示了
main.A[typing.Sequence*[builtins.int*]]
。(Apparently星号标记在类型变量替换期间推断的类型。)相关问题 更多 >
编程相关推荐