Skip to content

Commit d05158d

Browse files
committed
🎨 simplify iinfo and finfo
1 parent c5a1205 commit d05158d

1 file changed

Lines changed: 16 additions & 54 deletions

File tree

‎src/numpy-stubs/_core/getlimits.pyi‎

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,15 @@ from types import GenericAlias
22
from typing import Final, Generic, Literal as L, overload
33
from typing_extensions import Self, TypeVar
44

5+
import _numtype as _nt
56
import numpy as np
6-
from _numtype import inexact32, inexact64, inexact64l
7-
from numpy._typing import _DTypeLike
8-
from numpy._typing._char_codes import (
9-
_CLongDoubleCodes as _CFloat64LCodes,
10-
_Complex64Codes,
11-
_Complex128Codes,
12-
_Float16Codes,
13-
_Float32Codes,
14-
_Float64Codes,
15-
_Int8Codes,
16-
_Int16Codes,
17-
_Int32Codes,
18-
_Int64Codes,
19-
_IntPCodes,
20-
_LongCodes,
21-
_LongDoubleCodes as _Float64LCodes,
22-
_UInt8Codes,
23-
_UInt16Codes,
24-
_UInt32Codes,
25-
_UInt64Codes,
26-
_UIntPCodes,
27-
_ULongCodes,
28-
)
297

308
__all__ = ["finfo", "iinfo"]
319

3210
###
3311

34-
_FloatingT_co = TypeVar("_FloatingT_co", bound=np.floating, default=np.floating, covariant=True)
3512
_IntegerT_co = TypeVar("_IntegerT_co", bound=np.integer, default=np.integer, covariant=True)
13+
_FloatingT_co = TypeVar("_FloatingT_co", bound=np.floating, default=np.floating, covariant=True)
3614

3715
###
3816

@@ -49,31 +27,23 @@ class iinfo(Generic[_IntegerT_co]):
4927

5028
#
5129
@overload
52-
def __init__(self, /, int_type: _IntegerT_co | _DTypeLike[_IntegerT_co]) -> None: ...
53-
@overload
54-
def __init__(self: iinfo[np.int8], /, int_type: _Int8Codes) -> None: ...
55-
@overload
56-
def __init__(self: iinfo[np.uint8], /, int_type: _UInt8Codes) -> None: ...
30+
def __init__(self, /, int_type: _IntegerT_co | _nt._ToDType[_IntegerT_co]) -> None: ...
5731
@overload
58-
def __init__(self: iinfo[np.int16], /, int_type: _Int16Codes) -> None: ...
32+
def __init__(self: iinfo[np.int8], /, int_type: _nt.ToDTypeInt8) -> None: ...
5933
@overload
60-
def __init__(self: iinfo[np.uint16], /, int_type: _UInt16Codes) -> None: ...
34+
def __init__(self: iinfo[np.uint8], /, int_type: _nt.ToDTypeUInt8) -> None: ...
6135
@overload
62-
def __init__(self: iinfo[np.int32], /, int_type: _Int32Codes) -> None: ...
36+
def __init__(self: iinfo[np.int16], /, int_type: _nt.ToDTypeInt16) -> None: ...
6337
@overload
64-
def __init__(self: iinfo[np.uint32], /, int_type: _UInt32Codes) -> None: ...
38+
def __init__(self: iinfo[np.uint16], /, int_type: _nt.ToDTypeUInt16) -> None: ...
6539
@overload
66-
def __init__(self: iinfo[np.int64], /, int_type: _Int64Codes) -> None: ...
40+
def __init__(self: iinfo[np.int32], /, int_type: _nt.ToDTypeInt32) -> None: ...
6741
@overload
68-
def __init__(self: iinfo[np.uint64], /, int_type: _UInt64Codes) -> None: ...
42+
def __init__(self: iinfo[np.uint32], /, int_type: _nt.ToDTypeUInt32) -> None: ...
6943
@overload
70-
def __init__(self: iinfo[np.long], /, int_type: _LongCodes) -> None: ...
44+
def __init__(self: iinfo[np.int64], /, int_type: _nt.ToDTypeInt64 | int) -> None: ...
7145
@overload
72-
def __init__(self: iinfo[np.ulong], /, int_type: _ULongCodes) -> None: ...
73-
@overload
74-
def __init__(self: iinfo[np.intp], /, int_type: int | type[int] | _IntPCodes) -> None: ...
75-
@overload
76-
def __init__(self: iinfo[np.uintp], /, int_type: _UIntPCodes) -> None: ...
46+
def __init__(self: iinfo[np.uint64], /, int_type: _nt.ToDTypeUInt64) -> None: ...
7747

7848
#
7949
@classmethod
@@ -106,23 +76,15 @@ class finfo(Generic[_FloatingT_co]):
10676

10777
#
10878
@overload
109-
def __new__(cls, dtype: _FloatingT_co | _DTypeLike[_FloatingT_co]) -> Self: ...
110-
@overload
111-
def __new__(cls, dtype: type[complex] | complex) -> finfo[np.float64]: ...
79+
def __new__(cls, dtype: _nt.ToDTypeFloat16) -> finfo[np.float16]: ...
11280
@overload
113-
def __new__(cls, dtype: np.float16 | _DTypeLike[np.float16] | _Float16Codes) -> finfo[np.float16]: ...
81+
def __new__(cls, dtype: _nt.ToDTypeFloat32 | _nt.ToDTypeComplex64) -> finfo[np.float32]: ...
11482
@overload
115-
def __new__(
116-
cls, dtype: inexact32 | _DTypeLike[inexact32] | _Float32Codes | _Complex64Codes
117-
) -> finfo[np.float32]: ...
83+
def __new__(cls, dtype: _nt.ToDTypeFloat64 | _nt.ToDTypeComplex128 | complex) -> finfo[np.float64]: ...
11884
@overload
119-
def __new__(
120-
cls, dtype: inexact64 | _DTypeLike[inexact64] | _Float64Codes | _Complex128Codes
121-
) -> finfo[np.float64]: ...
85+
def __new__(cls, dtype: _nt.ToDTypeLongDouble | _nt.ToDTypeCLongDouble) -> finfo[np.longdouble]: ...
12286
@overload
123-
def __new__(
124-
cls, dtype: inexact64l | _DTypeLike[inexact64l] | _Float64LCodes | _CFloat64LCodes
125-
) -> finfo[np.longdouble]: ...
87+
def __new__(cls, dtype: _FloatingT_co | _nt._ToDType[_FloatingT_co]) -> Self: ...
12688

12789
#
12890
@classmethod

0 commit comments

Comments
 (0)