不兼容的返回类型[7]:预期`varible [t]
PYRE类型失败,因为当我们返回T时,它假设返回类型R不正确。 当我们在另一类中使用派生类并访问从父类中键入的通用字段时,就会发生这种情况。
以下是在最后一行投诉的玩具代码。
T = TypeVar("T")
R = TypeVar("R")
@dataclass(frozen=True)
class A(Generic[T, R]):
t: T
r: R
class B(A[T, R]):
...
@dataclass(frozen=True)
class X(Generic[T, R]):
a: A[T, R]
b: B[T, R]
def getfromA(self) -> T:
return self.a.t
def getfromB(self) -> T:
# pyre-fixe[7] Incompatible return type [7]: Expected `Variable[T]` but got `Variable[R]`.Pyre
return self.b.t
请注意,使用a,带有通用的基类时,它可以正常工作。 但是,当与B(派生类)一起使用时,它会反转类型。
我是想念什么还是撞到了一些已知的pyre错误?
谢谢
Pyre type fails because it assumes an incorrect return type R when we are returning T.
It happens when we use a derived class in another class and access a field that is generic typed from the parent class.
Following is the toy code for which it is complaining at the last line.
T = TypeVar("T")
R = TypeVar("R")
@dataclass(frozen=True)
class A(Generic[T, R]):
t: T
r: R
class B(A[T, R]):
...
@dataclass(frozen=True)
class X(Generic[T, R]):
a: A[T, R]
b: B[T, R]
def getfromA(self) -> T:
return self.a.t
def getfromB(self) -> T:
# pyre-fixe[7] Incompatible return type [7]: Expected `Variable[T]` but got `Variable[R]`.Pyre
return self.b.t
Notice that it works correctly when using A, the base class with generic.
But when using with B, the derived class, it inverts the types.
Am I missing something or am I hitting some known pyre bug?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论