Skip to content

Commit 292def7

Browse files
authored
Merge pull request #507 from numpy/testgen/less-aggressive-join
2 parents 577bff4 + dc10ebd commit 292def7

File tree

4 files changed

+45
-32
lines changed

4 files changed

+45
-32
lines changed

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

Lines changed: 5 additions & 5 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_arithmetic.pyi

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

src/numpy-stubs/__init__.pyi

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4714,15 +4714,15 @@ class number(
47144714

47154715
#
47164716
@overload
4717-
def __truediv__(self, x: _nt.CoFloating_0d | _nt.CastsScalar[Self] | _JustNumber, /) -> inexact: ...
4717+
def __truediv__(self, x: _nt.CoFloat64_0d | _nt.CastsScalar[Self] | _JustNumber, /) -> inexact: ...
47184718
@overload
47194719
def __truediv__(self, x: _nt.CastsWithScalar[Self, _InexactT], /) -> _InexactT: ...
47204720
@overload
47214721
def __truediv__(self: _nt.CastsWithComplex[_ComplexFloatingT], x: _nt.JustComplex, /) -> _ComplexFloatingT: ...
47224722

47234723
#
47244724
@overload
4725-
def __rtruediv__(self, x: _nt.CoFloating_0d | _nt.CastsScalar[Self] | _JustNumber, /) -> inexact: ...
4725+
def __rtruediv__(self, x: _nt.CoFloat64_0d | _nt.CastsScalar[Self] | _JustNumber, /) -> inexact: ...
47264726
@overload
47274727
def __rtruediv__(self, x: _nt.CastsWithScalar[Self, _InexactT], /) -> _InexactT: ...
47284728
@overload
@@ -5136,9 +5136,6 @@ class floating(_RealMixin, _RoundMixin, inexact[_BitT, float]):
51365136
@override
51375137
@type_check_only
51385138
def __nep50_rule3__(self, other: _JustFloating, /) -> floating: ...
5139-
@override
5140-
@type_check_only
5141-
def __nep50_rule4__(self, other: _JustComplexFloating, /) -> complexfloating: ...
51425139

51435140
#
51445141
@override
@@ -5245,7 +5242,12 @@ double = float64
52455242
class longdouble(_FloatMixin[L[12, 16]], floating[_n._64L]):
52465243
@override
52475244
@type_check_only
5248-
def __nep50__(self, below: _nt.inexact64l, above: _float64_max | _nt.co_integer, /) -> longdouble: ...
5245+
def __nep50__(
5246+
self,
5247+
below: longdouble | clongdouble,
5248+
above: _nt.co_float64,
5249+
/,
5250+
) -> longdouble: ...
52495251
@override
52505252
@type_check_only
52515253
def __nep50_complex__(self, /) -> clongdouble: ...
@@ -5255,6 +5257,9 @@ class longdouble(_FloatMixin[L[12, 16]], floating[_n._64L]):
52555257
@override
52565258
@type_check_only
52575259
def __nep50_rule4__(self, other: complexfloating | _JustComplexFloating, /) -> clongdouble: ...
5260+
@override
5261+
@type_check_only
5262+
def __nep50_rule6__(self, other: _JustInexact | _JustNumber, /) -> longdouble | clongdouble: ...
52585263

52595264
#
52605265
@overload

tool/testgen.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,18 @@ def _union(*types: str) -> str:
262262

263263
def _join(*types: str) -> str:
264264
"""Find the common base type, i.e. union + upcast."""
265+
if len(types) == 1:
266+
return types[0]
267+
265268
numbers, other = __group_types(*types)
266269
if other and numbers:
267270
raise NotImplementedError(f"join of non-number types: {types}")
268271

272+
if len(types) == len(numbers) == 2 and not other:
273+
# union two types if they're different kinds, e.g. `np.int8 | np.uint8` instead
274+
# of `np.integer`
275+
return " | ".join(kind_types[0] for kind_types in numbers.values())
276+
269277
# special case for accidental `bool` return from `timedelta64.__eq__` on numpy <2.3
270278
if not numbers and len(other) == 2 and set(other) == {f"{NP}.bool", "bool"}:
271279
return f"{NP}.bool"

0 commit comments

Comments
 (0)