-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Closed
Milestone
Description
Describe the issue:
This (sort of) came up in python/mypy#3186 (comment) recently, but _ComparisonOp's current form likely frustrates numeric interoperability. From here:
class _ComparisonOp(Protocol[_T1, _T2]):
@overload
def __call__(self, __other: _T1) -> bool_: ...
@overload
def __call__(self, __other: _T2) -> _ArrayOrScalar[bool_]: ...This may be well beyond the scope of what is possible with NumPy or Mypy (in which case, this should probably be closed as WONTFIX), but it does present a challenge. As long as one confines oneself to scalars on either side of the comparison, I'm pretty sure numpy will never return an array. I don't think that notion is sufficiently captured by the above.
Reproduce the code example:
# test_comparison.py
import numpy as np
from fractions import Fraction
assert np.int64(0) < Fraction(1) is True # type error, but runs okayError message:
test_comparison.py:5: error: No overload variant of "__call__" of "_ComparisonOp" matches argument type "Fraction" [call-overload]
test_comparison.py:5: note: Possible overload variants:
test_comparison.py:5: note: def __call__(self, Union[int, float, complex, number[Any], bool_]) -> bool_
test_comparison.py:5: note: def __call__(self, Union[_SupportsArray[dtype[Union[bool_, number[Any]]]], _NestedSequence[_SupportsArray[dtype[Union[bool_, number[Any]]]]], bool, int, float, complex, _NestedSequence[Union[bool, int, float, complex]]]) -> ndarray[Any, dtype[bool_]]
Found 1 error in 1 file (checked 1 source file)NumPy/Python version information:
1.23.0 3.10.5 (main, Jun 7 2022, 08:51:33) [Clang 13.0.0 (clang-1300.0.29.30)]