Skip to content

Commit 27574f8

Browse files
authored
Merge pull request numpy#27334 from jorenham/typing/scalar_builtin_base
TYP: Concrete ``float64`` and ``complex128`` scalar types with builtin bases
2 parents ee67adf + 4c3ceaa commit 27574f8

File tree

10 files changed

+300
-107
lines changed

10 files changed

+300
-107
lines changed

numpy/__init__.pyi

Lines changed: 204 additions & 20 deletions
Large diffs are not rendered by default.

numpy/typing/tests/data/fail/arithmetic.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ td = np.timedelta64(0, "D")
1010
AR_b: npt.NDArray[np.bool]
1111
AR_u: npt.NDArray[np.uint32]
1212
AR_i: npt.NDArray[np.int64]
13-
AR_f: npt.NDArray[np.float64]
13+
AR_f: npt.NDArray[np.longdouble]
1414
AR_c: npt.NDArray[np.complex128]
1515
AR_m: npt.NDArray[np.timedelta64]
1616
AR_M: npt.NDArray[np.datetime64]

numpy/typing/tests/data/pass/arithmetic.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import Any
44
import numpy as np
5+
import numpy.typing as npt
56
import pytest
67

78
c16 = np.complex128(1)
@@ -57,14 +58,14 @@ def __rpow__(self, value: Any) -> Object:
5758
return self
5859

5960

60-
AR_b: np.ndarray[Any, np.dtype[np.bool]] = np.array([True])
61-
AR_u: np.ndarray[Any, np.dtype[np.uint32]] = np.array([1], dtype=np.uint32)
62-
AR_i: np.ndarray[Any, np.dtype[np.int64]] = np.array([1])
63-
AR_f: np.ndarray[Any, np.dtype[np.float64]] = np.array([1.0])
64-
AR_c: np.ndarray[Any, np.dtype[np.complex128]] = np.array([1j])
65-
AR_m: np.ndarray[Any, np.dtype[np.timedelta64]] = np.array([np.timedelta64(1, "D")])
66-
AR_M: np.ndarray[Any, np.dtype[np.datetime64]] = np.array([np.datetime64(1, "D")])
67-
AR_O: np.ndarray[Any, np.dtype[np.object_]] = np.array([Object()])
61+
AR_b: npt.NDArray[np.bool] = np.array([True])
62+
AR_u: npt.NDArray[np.uint32] = np.array([1], dtype=np.uint32)
63+
AR_i: npt.NDArray[np.int64] = np.array([1])
64+
AR_f: npt.NDArray[np.float64] = np.array([1.0])
65+
AR_c: npt.NDArray[np.complex128] = np.array([1j])
66+
AR_m: npt.NDArray[np.timedelta64] = np.array([np.timedelta64(1, "D")])
67+
AR_M: npt.NDArray[np.datetime64] = np.array([np.datetime64(1, "D")])
68+
AR_O: npt.NDArray[np.object_] = np.array([Object()])
6869

6970
AR_LIKE_b = [True]
7071
AR_LIKE_u = [np.uint32(1)]

numpy/typing/tests/data/reveal/arithmetic.pyi

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -345,102 +345,102 @@ assert_type(c8 / b_, np.complex64)
345345

346346
# Complex
347347

348-
assert_type(c16 + f16, np.complexfloating[_64Bit, _64Bit] | np.complexfloating[_128Bit, _128Bit])
348+
assert_type(c16 + f16, np.complex128 | np.complexfloating[_128Bit, _128Bit])
349349
assert_type(c16 + c16, np.complex128)
350350
assert_type(c16 + f8, np.complex128)
351351
assert_type(c16 + i8, np.complex128)
352-
assert_type(c16 + c8, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
353-
assert_type(c16 + f4, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
354-
assert_type(c16 + i4, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
352+
assert_type(c16 + c8, np.complexfloating[_64Bit, _64Bit])
353+
assert_type(c16 + f4, np.complex128 | np.complex64)
354+
assert_type(c16 + i4, np.complex128 | np.complex64)
355355
assert_type(c16 + b_, np.complex128)
356356
assert_type(c16 + b, np.complex128)
357357
assert_type(c16 + c, np.complex128)
358358
assert_type(c16 + f, np.complex128)
359359
assert_type(c16 + AR_f, npt.NDArray[np.complexfloating[Any, Any]])
360360

361-
assert_type(f16 + c16, np.complexfloating[_64Bit, _64Bit] | np.complexfloating[_128Bit, _128Bit])
361+
assert_type(f16 + c16, np.complex128 | np.complexfloating[_128Bit, _128Bit])
362362
assert_type(c16 + c16, np.complex128)
363363
assert_type(f8 + c16, np.complex128)
364-
assert_type(i8 + c16, np.complex128)
365-
assert_type(c8 + c16, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
366-
assert_type(f4 + c16, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
367-
assert_type(i4 + c16, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
364+
assert_type(i8 + c16, np.complexfloating[_64Bit, _64Bit])
365+
assert_type(c8 + c16, np.complex128 | np.complex64)
366+
assert_type(f4 + c16, np.complex128 | np.complex64)
367+
assert_type(i4 + c16, np.complex128 | np.complex64)
368368
assert_type(b_ + c16, np.complex128)
369369
assert_type(b + c16, np.complex128)
370370
assert_type(c + c16, np.complex128)
371371
assert_type(f + c16, np.complex128)
372372
assert_type(AR_f + c16, npt.NDArray[np.complexfloating[Any, Any]])
373373

374374
assert_type(c8 + f16, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_128Bit, _128Bit])
375-
assert_type(c8 + c16, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
376-
assert_type(c8 + f8, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
375+
assert_type(c8 + c16, np.complex64 | np.complex128)
376+
assert_type(c8 + f8, np.complex64 | np.complex128)
377377
assert_type(c8 + i8, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
378378
assert_type(c8 + c8, np.complex64)
379379
assert_type(c8 + f4, np.complex64)
380380
assert_type(c8 + i4, np.complex64)
381381
assert_type(c8 + b_, np.complex64)
382382
assert_type(c8 + b, np.complex64)
383-
assert_type(c8 + c, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
384-
assert_type(c8 + f, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
383+
assert_type(c8 + c, np.complex64 | np.complex128)
384+
assert_type(c8 + f, np.complex64 | np.complex128)
385385
assert_type(c8 + AR_f, npt.NDArray[np.complexfloating[Any, Any]])
386386

387387
assert_type(f16 + c8, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_128Bit, _128Bit])
388-
assert_type(c16 + c8, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
389-
assert_type(f8 + c8, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
388+
assert_type(c16 + c8, np.complexfloating[_64Bit, _64Bit])
389+
assert_type(f8 + c8, np.complexfloating[_64Bit, _64Bit])
390390
assert_type(i8 + c8, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
391391
assert_type(c8 + c8, np.complex64)
392392
assert_type(f4 + c8, np.complex64)
393393
assert_type(i4 + c8, np.complex64)
394394
assert_type(b_ + c8, np.complex64)
395395
assert_type(b + c8, np.complex64)
396-
assert_type(c + c8, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
397-
assert_type(f + c8, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
396+
assert_type(c + c8, np.complex64 | np.complex128)
397+
assert_type(f + c8, np.complex64 | np.complex128)
398398
assert_type(AR_f + c8, npt.NDArray[np.complexfloating[Any, Any]])
399399

400400
# Float
401401

402-
assert_type(f8 + f16, np.floating[_64Bit] | np.floating[_128Bit])
402+
assert_type(f8 + f16, np.float64| np.floating[_128Bit])
403403
assert_type(f8 + f8, np.float64)
404404
assert_type(f8 + i8, np.float64)
405-
assert_type(f8 + f4, np.floating[_32Bit] | np.floating[_64Bit])
406-
assert_type(f8 + i4, np.floating[_32Bit] | np.floating[_64Bit])
405+
assert_type(f8 + f4, np.float64 | np.floating[_32Bit])
406+
assert_type(f8 + i4, np.float64 | np.floating[_32Bit])
407407
assert_type(f8 + b_, np.float64)
408408
assert_type(f8 + b, np.float64)
409-
assert_type(f8 + c, np.complex128)
409+
assert_type(f8 + c, np.float64 | np.complex128)
410410
assert_type(f8 + f, np.float64)
411411
assert_type(f8 + AR_f, npt.NDArray[np.floating[Any]])
412412

413-
assert_type(f16 + f8, np.floating[_64Bit] | np.floating[_128Bit])
413+
assert_type(f16 + f8, np.floating[_128Bit] | np.float64)
414414
assert_type(f8 + f8, np.float64)
415-
assert_type(i8 + f8, np.float64)
416-
assert_type(f4 + f8, np.floating[_32Bit] | np.floating[_64Bit])
417-
assert_type(i4 + f8, np.floating[_32Bit] | np.floating[_64Bit])
415+
assert_type(i8 + f8, np.floating[_64Bit])
416+
assert_type(f4 + f8, np.floating[_32Bit] | np.float64)
417+
assert_type(i4 + f8, np.floating[_32Bit] | np.float64)
418418
assert_type(b_ + f8, np.float64)
419419
assert_type(b + f8, np.float64)
420-
assert_type(c + f8, np.complex128)
420+
assert_type(c + f8, np.complex128 | np.float64)
421421
assert_type(f + f8, np.float64)
422422
assert_type(AR_f + f8, npt.NDArray[np.floating[Any]])
423423

424-
assert_type(f4 + f16, np.floating[_32Bit] | np.floating[_128Bit])
425-
assert_type(f4 + f8, np.floating[_32Bit] | np.floating[_64Bit])
426-
assert_type(f4 + i8, np.floating[_32Bit] | np.floating[_64Bit])
424+
assert_type(f4 + f16, np.float32 | np.floating[_128Bit])
425+
assert_type(f4 + f8, np.float32 | np.float64)
426+
assert_type(f4 + i8, np.float32 | np.floating[_64Bit])
427427
assert_type(f4 + f4, np.float32)
428428
assert_type(f4 + i4, np.float32)
429429
assert_type(f4 + b_, np.float32)
430430
assert_type(f4 + b, np.float32)
431-
assert_type(f4 + c, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
432-
assert_type(f4 + f, np.floating[_32Bit] | np.floating[_64Bit])
431+
assert_type(f4 + c, np.complex64 | np.complex128)
432+
assert_type(f4 + f, np.float32 | np.float64)
433433
assert_type(f4 + AR_f, npt.NDArray[np.floating[Any]])
434434

435-
assert_type(f16 + f4, np.floating[_32Bit] | np.floating[_128Bit])
436-
assert_type(f8 + f4, np.floating[_32Bit] | np.floating[_64Bit])
435+
assert_type(f16 + f4, np.floating[_128Bit] | np.float32)
436+
assert_type(f8 + f4, np.float64 | np.float32)
437437
assert_type(i8 + f4, np.floating[_32Bit] | np.floating[_64Bit])
438438
assert_type(f4 + f4, np.float32)
439439
assert_type(i4 + f4, np.float32)
440440
assert_type(b_ + f4, np.float32)
441441
assert_type(b + f4, np.float32)
442-
assert_type(c + f4, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit])
443-
assert_type(f + f4, np.floating[_32Bit] | np.floating[_64Bit])
442+
assert_type(c + f4, np.complex64 | np.complex128)
443+
assert_type(f + f4, np.float64 | np.float32)
444444
assert_type(AR_f + f4, npt.NDArray[np.floating[Any]])
445445

446446
# Int
@@ -451,17 +451,17 @@ assert_type(i8 + i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit])
451451
assert_type(i8 + u4, Any)
452452
assert_type(i8 + b_, np.int64)
453453
assert_type(i8 + b, np.int64)
454-
assert_type(i8 + c, np.complex128)
455-
assert_type(i8 + f, np.float64)
454+
assert_type(i8 + c, np.complexfloating[_64Bit, _64Bit])
455+
assert_type(i8 + f, np.floating[_64Bit])
456456
assert_type(i8 + AR_f, npt.NDArray[np.floating[Any]])
457457

458458
assert_type(u8 + u8, np.uint64)
459459
assert_type(u8 + i4, Any)
460460
assert_type(u8 + u4, np.unsignedinteger[_32Bit] | np.unsignedinteger[_64Bit])
461461
assert_type(u8 + b_, np.uint64)
462462
assert_type(u8 + b, np.uint64)
463-
assert_type(u8 + c, np.complex128)
464-
assert_type(u8 + f, np.float64)
463+
assert_type(u8 + c, np.complexfloating[_64Bit, _64Bit])
464+
assert_type(u8 + f, np.floating[_64Bit])
465465
assert_type(u8 + AR_f, npt.NDArray[np.floating[Any]])
466466

467467
assert_type(i8 + i8, np.int64)
@@ -470,17 +470,17 @@ assert_type(i4 + i8, np.signedinteger[_32Bit] | np.signedinteger[_64Bit])
470470
assert_type(u4 + i8, Any)
471471
assert_type(b_ + i8, np.int64)
472472
assert_type(b + i8, np.int64)
473-
assert_type(c + i8, np.complex128)
474-
assert_type(f + i8, np.float64)
473+
assert_type(c + i8, np.complexfloating[_64Bit, _64Bit])
474+
assert_type(f + i8, np.floating[_64Bit])
475475
assert_type(AR_f + i8, npt.NDArray[np.floating[Any]])
476476

477477
assert_type(u8 + u8, np.uint64)
478478
assert_type(i4 + u8, Any)
479479
assert_type(u4 + u8, np.unsignedinteger[_32Bit] | np.unsignedinteger[_64Bit])
480480
assert_type(b_ + u8, np.uint64)
481481
assert_type(b + u8, np.uint64)
482-
assert_type(c + u8, np.complex128)
483-
assert_type(f + u8, np.float64)
482+
assert_type(c + u8, np.complexfloating[_64Bit, _64Bit])
483+
assert_type(f + u8, np.floating[_64Bit])
484484
assert_type(AR_f + u8, npt.NDArray[np.floating[Any]])
485485

486486
assert_type(i4 + i8, np.signedinteger[_32Bit] | np.signedinteger[_64Bit])

numpy/typing/tests/data/reveal/arraysetops.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import numpy.typing as npt
55
from numpy.lib._arraysetops_impl import (
66
UniqueAllResult, UniqueCountsResult, UniqueInverseResult
77
)
8+
from numpy._typing import _64Bit
89

910
from typing_extensions import assert_type
1011

@@ -25,7 +26,10 @@ assert_type(np.ediff1d(AR_LIKE_f8, to_begin=[1, 1.5]), npt.NDArray[Any])
2526
assert_type(np.intersect1d(AR_i8, AR_i8), npt.NDArray[np.int64])
2627
assert_type(np.intersect1d(AR_M, AR_M, assume_unique=True), npt.NDArray[np.datetime64])
2728
assert_type(np.intersect1d(AR_f8, AR_i8), npt.NDArray[Any])
28-
assert_type(np.intersect1d(AR_f8, AR_f8, return_indices=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp], npt.NDArray[np.intp]])
29+
assert_type(
30+
np.intersect1d(AR_f8, AR_f8, return_indices=True),
31+
tuple[npt.NDArray[np.floating[_64Bit]], npt.NDArray[np.intp], npt.NDArray[np.intp]],
32+
)
2933

3034
assert_type(np.setxor1d(AR_i8, AR_i8), npt.NDArray[np.int64])
3135
assert_type(np.setxor1d(AR_M, AR_M, assume_unique=True), npt.NDArray[np.datetime64])

numpy/typing/tests/data/reveal/getlimits.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any
22

33
import numpy as np
4+
from numpy._typing import _64Bit
45

56
from typing_extensions import assert_type, LiteralString
67

@@ -15,8 +16,8 @@ u4: np.uint32
1516
finfo_f8: np.finfo[np.float64]
1617
iinfo_i8: np.iinfo[np.int64]
1718

18-
assert_type(np.finfo(f), np.finfo[np.double])
19-
assert_type(np.finfo(f8), np.finfo[np.float64])
19+
assert_type(np.finfo(f), np.finfo[np.float64])
20+
assert_type(np.finfo(f8), np.finfo[np.floating[_64Bit]])
2021
assert_type(np.finfo(c8), np.finfo[np.float32])
2122
assert_type(np.finfo('f2'), np.finfo[np.floating[Any]])
2223

numpy/typing/tests/data/reveal/mod.pyi

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,57 +75,57 @@ assert_type(divmod(AR_b, b_), tuple[npt.NDArray[np.int8], npt.NDArray[np.int8]])
7575
# int
7676

7777
assert_type(i8 % b, np.int64)
78-
assert_type(i8 % f, np.float64)
7978
assert_type(i8 % i8, np.int64)
80-
assert_type(i8 % f8, np.float64)
81-
assert_type(i4 % i8, np.signedinteger[_32Bit] | np.signedinteger[_64Bit])
82-
assert_type(i4 % f8, np.floating[_32Bit] | np.floating[_64Bit])
79+
assert_type(i8 % f, np.floating[_64Bit])
80+
assert_type(i8 % f8, np.floating[_64Bit])
81+
assert_type(i4 % i8, np.int64 | np.int32)
82+
assert_type(i4 % f8, np.float64 | np.float32)
8383
assert_type(i4 % i4, np.int32)
8484
assert_type(i4 % f4, np.float32)
8585
assert_type(i8 % AR_b, npt.NDArray[np.signedinteger[Any]])
8686

87-
assert_type(divmod(i8, b), tuple[np.int64, np.int64])
88-
assert_type(divmod(i8, f), tuple[np.float64, np.float64])
89-
assert_type(divmod(i8, i8), tuple[np.int64, np.int64])
90-
assert_type(divmod(i8, f8), tuple[np.float64, np.float64])
91-
assert_type(divmod(i8, i4), tuple[np.signedinteger[_32Bit], np.signedinteger[_32Bit]] | tuple[np.signedinteger[_64Bit], np.signedinteger[_64Bit]])
92-
assert_type(divmod(i8, f4), tuple[np.floating[_32Bit], np.floating[_32Bit]] | tuple[np.floating[_64Bit], np.floating[_64Bit]])
93-
assert_type(divmod(i4, i4), tuple[np.int32, np.int32])
94-
assert_type(divmod(i4, f4), tuple[np.float32, np.float32])
87+
assert_type(divmod(i8, b), tuple[np.signedinteger[_64Bit], np.signedinteger[_64Bit]])
88+
assert_type(divmod(i8, f), tuple[np.floating[_64Bit], np.floating[_64Bit]])
89+
assert_type(divmod(i8, i8), tuple[np.signedinteger[_64Bit], np.signedinteger[_64Bit]])
90+
assert_type(divmod(i8, f8), tuple[np.floating[_64Bit], np.floating[_64Bit]])
91+
assert_type(divmod(i8, i4), tuple[np.signedinteger[_64Bit], np.signedinteger[_64Bit]] | tuple[np.signedinteger[_32Bit], np.signedinteger[_32Bit]])
92+
assert_type(divmod(i8, f4), tuple[np.floating[_64Bit], np.floating[_64Bit]] | tuple[np.floating[_32Bit], np.floating[_32Bit]])
93+
assert_type(divmod(i4, i4), tuple[np.signedinteger[_32Bit], np.signedinteger[_32Bit]])
94+
assert_type(divmod(i4, f4), tuple[np.floating[_32Bit], np.floating[_32Bit]])
9595
assert_type(divmod(i8, AR_b), tuple[npt.NDArray[np.signedinteger[Any]], npt.NDArray[np.signedinteger[Any]]])
9696

97-
assert_type(b % i8, np.int64)
98-
assert_type(f % i8, np.float64)
97+
assert_type(b % i8, np.signedinteger[_64Bit])
98+
assert_type(f % i8, np.floating[_64Bit])
9999
assert_type(i8 % i8, np.int64)
100100
assert_type(f8 % i8, np.float64)
101-
assert_type(i8 % i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit])
102-
assert_type(f8 % i4, np.floating[_32Bit] | np.floating[_64Bit])
101+
assert_type(i8 % i4, np.int64 | np.int32)
102+
assert_type(f8 % i4, np.float64 | np.float32)
103103
assert_type(i4 % i4, np.int32)
104104
assert_type(f4 % i4, np.float32)
105105
assert_type(AR_b % i8, npt.NDArray[np.signedinteger[Any]])
106106

107-
assert_type(divmod(b, i8), tuple[np.int64, np.int64])
108-
assert_type(divmod(f, i8), tuple[np.float64, np.float64])
107+
assert_type(divmod(b, i8), tuple[np.signedinteger[_64Bit], np.signedinteger[_64Bit]])
108+
assert_type(divmod(f, i8), tuple[np.floating[_64Bit], np.floating[_64Bit]])
109109
assert_type(divmod(i8, i8), tuple[np.int64, np.int64])
110110
assert_type(divmod(f8, i8), tuple[np.float64, np.float64])
111-
assert_type(divmod(i4, i8), tuple[np.signedinteger[_32Bit], np.signedinteger[_32Bit]] | tuple[np.signedinteger[_64Bit], np.signedinteger[_64Bit]])
112-
assert_type(divmod(f4, i8), tuple[np.floating[_32Bit], np.floating[_32Bit]] | tuple[np.floating[_64Bit], np.floating[_64Bit]])
113-
assert_type(divmod(i4, i4), tuple[np.int32, np.int32])
114-
assert_type(divmod(f4, i4), tuple[np.float32, np.float32])
111+
assert_type(divmod(i4, i8), tuple[np.signedinteger[_64Bit], np.signedinteger[_64Bit]] | tuple[np.signedinteger[_32Bit], np.signedinteger[_32Bit]])
112+
assert_type(divmod(f4, i8), tuple[np.floating[_64Bit], np.floating[_64Bit]] | tuple[np.floating[_32Bit], np.floating[_32Bit]])
113+
assert_type(divmod(i4, i4), tuple[np.signedinteger[_32Bit], np.signedinteger[_32Bit]])
114+
assert_type(divmod(f4, i4), tuple[np.floating[_32Bit], np.floating[_32Bit]])
115115
assert_type(divmod(AR_b, i8), tuple[npt.NDArray[np.signedinteger[Any]], npt.NDArray[np.signedinteger[Any]]])
116116

117117
# float
118118

119119
assert_type(f8 % b, np.float64)
120120
assert_type(f8 % f, np.float64)
121-
assert_type(i8 % f4, np.floating[_32Bit] | np.floating[_64Bit])
121+
assert_type(i8 % f4, np.floating[_64Bit] | np.floating[_32Bit])
122122
assert_type(f4 % f4, np.float32)
123123
assert_type(f8 % AR_b, npt.NDArray[np.floating[Any]])
124124

125125
assert_type(divmod(f8, b), tuple[np.float64, np.float64])
126126
assert_type(divmod(f8, f), tuple[np.float64, np.float64])
127127
assert_type(divmod(f8, f8), tuple[np.float64, np.float64])
128-
assert_type(divmod(f8, f4), tuple[np.floating[_32Bit], np.floating[_32Bit]] | tuple[np.floating[_64Bit], np.floating[_64Bit]])
128+
assert_type(divmod(f8, f4), tuple[np.float64, np.float64] | tuple[np.float32, np.float32])
129129
assert_type(divmod(f4, f4), tuple[np.float32, np.float32])
130130
assert_type(divmod(f8, AR_b), tuple[npt.NDArray[np.floating[Any]], npt.NDArray[np.floating[Any]]])
131131

@@ -139,6 +139,6 @@ assert_type(AR_b % f8, npt.NDArray[np.floating[Any]])
139139
assert_type(divmod(b, f8), tuple[np.float64, np.float64])
140140
assert_type(divmod(f, f8), tuple[np.float64, np.float64])
141141
assert_type(divmod(f8, f8), tuple[np.float64, np.float64])
142-
assert_type(divmod(f4, f8), tuple[np.floating[_32Bit], np.floating[_32Bit]] | tuple[np.floating[_64Bit], np.floating[_64Bit]])
142+
assert_type(divmod(f4, f8), tuple[np.float64, np.float64] | tuple[np.float32, np.float32])
143143
assert_type(divmod(f4, f4), tuple[np.float32, np.float32])
144144
assert_type(divmod(AR_b, f8), tuple[npt.NDArray[np.floating[Any]], npt.NDArray[np.floating[Any]]])

numpy/typing/tests/data/reveal/nbit_base_example.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ i4: np.int32
1717
f8: np.float64
1818
f4: np.float32
1919

20-
assert_type(add(f8, i8), np.float64)
20+
assert_type(add(f8, i8), np.floating[_64Bit])
2121
assert_type(add(f4, i8), np.floating[_32Bit | _64Bit])
2222
assert_type(add(f8, i4), np.floating[_32Bit | _64Bit])
23-
assert_type(add(f4, i4), np.float32)
23+
assert_type(add(f4, i4), np.floating[_32Bit])

numpy/typing/tests/data/reveal/polynomial_polyutils.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ assert_type(pu.mapparms(seq_num_object, seq_num_object), _Tuple2[object])
159159

160160
assert_type(pu.mapparms(seq_sct_int, seq_sct_int), _Tuple2[np.floating[Any]])
161161
assert_type(pu.mapparms(seq_sct_int, seq_sct_float), _Tuple2[np.floating[Any]])
162-
assert_type(pu.mapparms(seq_sct_float, seq_sct_float), _Tuple2[np.floating[Any]])
163-
assert_type(pu.mapparms(seq_sct_float, seq_sct_complex), _Tuple2[np.complexfloating[Any, Any]])
164-
assert_type(pu.mapparms(seq_sct_complex, seq_sct_complex), _Tuple2[np.complexfloating[Any, Any]])
162+
assert_type(pu.mapparms(seq_sct_float, seq_sct_float), _Tuple2[float])
163+
assert_type(pu.mapparms(seq_sct_float, seq_sct_complex), _Tuple2[complex])
164+
assert_type(pu.mapparms(seq_sct_complex, seq_sct_complex), _Tuple2[complex])
165165
assert_type(pu.mapparms(seq_sct_complex, seq_sct_object), _Tuple2[object])
166166
assert_type(pu.mapparms(seq_sct_object, seq_sct_object), _Tuple2[object])
167167

numpy/typing/tests/data/reveal/type_check.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ assert_type(np.nan_to_num(AR_f8, nan=1.5), npt.NDArray[np.float64])
5555
assert_type(np.nan_to_num(AR_LIKE_f, posinf=9999), npt.NDArray[Any])
5656

5757
assert_type(np.real_if_close(AR_f8), npt.NDArray[np.float64])
58-
assert_type(np.real_if_close(AR_c16), npt.NDArray[np.float64] | npt.NDArray[np.complex128])
58+
assert_type(
59+
np.real_if_close(AR_c16),
60+
npt.NDArray[np.floating[_64Bit]] | npt.NDArray[np.complexfloating[_64Bit, _64Bit]],
61+
)
5962
assert_type(np.real_if_close(AR_c8), npt.NDArray[np.float32] | npt.NDArray[np.complex64])
6063
assert_type(np.real_if_close(AR_LIKE_f), npt.NDArray[Any])
6164

@@ -64,7 +67,7 @@ assert_type(np.typename("B"), Literal["unsigned char"])
6467
assert_type(np.typename("V"), Literal["void"])
6568
assert_type(np.typename("S1"), Literal["character"])
6669

67-
assert_type(np.common_type(AR_i4), type[np.float64])
70+
assert_type(np.common_type(AR_i4), type[np.floating[_64Bit]])
6871
assert_type(np.common_type(AR_f2), type[np.float16])
6972
assert_type(np.common_type(AR_f2, AR_i4), type[np.floating[_16Bit | _64Bit]])
7073
assert_type(np.common_type(AR_f16, AR_i4), type[np.floating[_64Bit | _128Bit]])

0 commit comments

Comments
 (0)