You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import numpy as np
from typing import Union
IntegerT = Union[np.integer, int]
def f(a: IntegerT, b: IntegerT) -> IntegerT:
return max(a, b)
$ mypy mypybug2.py
mypybug2.py:7: error: Value of type variable "SupportsRichComparisonT" of "max" cannot be "integer[Any] | int" [type-var]
Found 1 error in 1 file (checked 1 source file)
I don't see anything wrong with the expression involving max, so the error is surprising. Even substituting a concrete integer type like np.int64 triggers the same error.
If I understand the problem correctly, the problem is that np.integer's comparison operators return np.bool, but the typeshed operator expect a "proper" Python bool. np.bool is not derived from bool and therefore incompatible. This is a problem with numpy's type annotations.
A possible fix is for numpy's type stubs to declare that np.bool derives from bool, even if it doesn't at runtime. But that's a decision the numpy project has to make.
I don't see anything wrong with the expression involving
max
, so the error is surprising. Even substituting a concrete integer type likenp.int64
triggers the same error.The text was updated successfully, but these errors were encountered: