Skip to content

Commit ff3a000

Browse files
authored
Merge pull request #500 from numpy/nep50-inexact-simplifications
2 parents cada4f8 + 0c899da commit ff3a000

File tree

8 files changed

+471
-1610
lines changed

8 files changed

+471
-1610
lines changed

src/_numtype/@test/test_nep50.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,4 +565,4 @@ cld_to_f8: CanCast0D[Any, np.clongdouble] = f8 # type: ignore[assignment] # py
565565
cld_to_ld: CanCast0D[Any, np.clongdouble] = ld # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
566566
cld_to_c8: CanCast0D[Any, np.clongdouble] = c8 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
567567
cld_to_c16: CanCast0D[Any, np.clongdouble] = c16 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
568-
cld_to_cld: CanCast0D[Any, np.clongdouble] = cld # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
568+
cld_to_cld: CanCast0D[Any, np.clongdouble] = cld # NOTE: allowing this simplifies the __nep50__ definition

src/_numtype/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ from ._nep50 import (
5151
CanCast0D as CanCast0D,
5252
CanCastND as CanCastND,
5353
CanNEP50 as CanNEP50,
54+
CanNEP50Complex as CanNEP50Complex,
55+
CanNEP50Float as CanNEP50Float,
5456
MatchND as MatchND,
5557
PromoteWith as PromoteWith,
5658
PromoteWith0D as PromoteWith0D,

src/_numtype/_nep50.pyi

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from typing_extensions import TypeAliasType, TypeVar
77

88
import numpy as np
99

10-
__all__ = ["CanCast0D", "CanCastND", "CanNEP50", "MatchND", "PromoteWith", "PromoteWith0D"]
10+
__all__ = ["CanCast0D", "CanCastND", "CanNEP50", "CanNEP50Complex", "CanNEP50Float", "MatchND", "PromoteWith", "PromoteWith0D"]
1111

1212
_T_co = TypeVar("_T_co", covariant=True)
1313
_BelowT_contra = TypeVar("_BelowT_contra", bound=np.generic, contravariant=True)
@@ -16,6 +16,9 @@ _OtherT_contra = TypeVar("_OtherT_contra", contravariant=True)
1616
_MatchT_co = TypeVar("_MatchT_co", bound=np.generic, covariant=True, default=Any)
1717
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)
1818

19+
_ComplexFloatingT_co = TypeVar("_ComplexFloatingT_co", bound=np.complexfloating, covariant=True)
20+
_InexactT_co = TypeVar("_InexactT_co", bound=np.inexact, covariant=True)
21+
1922
@type_check_only
2023
class CanNEP50(Protocol[_BelowT_contra, _AboveT_contra, _MatchT_co]):
2124
def __nep50__(self, below: _BelowT_contra, above: _AboveT_contra, /) -> _MatchT_co: ...
@@ -44,6 +47,18 @@ class _CanNEP50Rule4(Protocol[_OtherT_contra, _T_co]):
4447
class _CanNEP50Rule5(Protocol[_OtherT_contra, _T_co]):
4548
def __nep50_rule5__(self, other: _OtherT_contra, /) -> _T_co: ...
4649

50+
@type_check_only
51+
class _CanNEP50Rule6(Protocol[_OtherT_contra, _T_co]):
52+
def __nep50_rule6__(self, other: _OtherT_contra, /) -> _T_co: ...
53+
54+
@type_check_only
55+
class CanNEP50Float(Protocol[_InexactT_co]):
56+
def __nep50_float__(self, /) -> _InexactT_co: ...
57+
58+
@type_check_only
59+
class CanNEP50Complex(Protocol[_ComplexFloatingT_co]):
60+
def __nep50_complex__(self, /) -> _ComplexFloatingT_co: ...
61+
4762
_WithT = TypeVar("_WithT")
4863
_OutT = TypeVar("_OutT", bound=np.generic)
4964

@@ -55,7 +70,8 @@ PromoteWith = TypeAliasType(
5570
| _CanNEP50Rule2[_WithT, _OutT]
5671
| _CanNEP50Rule3[_WithT, _OutT]
5772
| _CanNEP50Rule4[_WithT, _OutT]
58-
| _CanNEP50Rule5[_WithT, _OutT],
73+
| _CanNEP50Rule5[_WithT, _OutT]
74+
| _CanNEP50Rule6[_WithT, _OutT],
5975
type_params=(_WithT, _OutT),
6076
)
6177
PromoteWith0D = TypeAliasType(

src/numpy-stubs/@test/generated/scalar_ops_arithmetic.pyi

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/numpy-stubs/@test/generated/scalar_ops_comparison.pyi

Lines changed: 1 addition & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)