【发布时间】:2022-01-08 23:47:22
【问题描述】:
我有一个如下所示的类:
import numpy as np
class TestClass():
def __init__(self, a: np.ndarray):
self.a = a
def __eq__(self, other: object) -> bool:
if not isinstance(other, TestClass):
raise TypeError
return (np.all(self.a == other.a))
Mypy 返回错误Incompatible return value type (got "Union[bool_, ndarray]", expected "bool")。根据documentation for np.all,这个函数应该返回一个带有这些类型输入的常规布尔值。这种行为有原因吗?
【问题讨论】:
标签: python type-hinting mypy