Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions numpy/_typing/_callable.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ from ._scalars import (
)
from . import NBitBase
from ._generic_alias import NDArray
from ._nested_sequence import _NestedSequence

_T1 = TypeVar("_T1")
_T2 = TypeVar("_T2")
Expand Down Expand Up @@ -318,8 +319,20 @@ class _ComplexOp(Protocol[_NBit1]):
class _NumberOp(Protocol):
def __call__(self, other: _NumberLike_co, /) -> Any: ...

class _SupportsLT(Protocol):
def __lt__(self, other: Any, /) -> object: ...

class _SupportsGT(Protocol):
def __gt__(self, other: Any, /) -> object: ...

class _ComparisonOp(Protocol[_T1_contra, _T2_contra]):
@overload
def __call__(self, other: _T1_contra, /) -> bool_: ...
@overload
def __call__(self, other: _T2_contra, /) -> NDArray[bool_]: ...
@overload
def __call__(
self,
other: _SupportsLT | _SupportsGT | _NestedSequence[_SupportsLT | _SupportsGT],
/,
) -> Any: ...
9 changes: 9 additions & 0 deletions numpy/typing/tests/data/reveal/comparisons.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import numpy as np
import fractions
import decimal

c16 = np.complex128()
f8 = np.float64()
Expand All @@ -25,6 +27,13 @@ AR.setflags(write=False)

SEQ = (0, 1, 2, 3, 4)

# object-like comparisons

reveal_type(i8 > fractions.Fraction(1, 5)) # E: Any
reveal_type(i8 > [fractions.Fraction(1, 5)]) # E: Any
reveal_type(i8 > decimal.Decimal("1.5")) # E: Any
reveal_type(i8 > [decimal.Decimal("1.5")]) # E: Any

# Time structures

reveal_type(dt > dt) # E: bool_
Expand Down