如何强制mypy的显示类型显示超级类型?

2024-09-28 17:16:35 发布

您现在位置:Python中文网/ 问答频道 /正文

Given

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的推断相矛盾),这将使事情变得更清楚


Tags: fromimporttyping类型参数typepassgiven