Skip to content

Commit 8c6752d

Browse files
authored
Merge pull request numpy#26994 from jorenham/typing/iinfo_finfo_covariant
TYP: Typing fixes for ``numpy.iinfo`` & ``numpy.finfo``
2 parents af75b6f + 303276a commit 8c6752d

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

numpy/__init__.pyi

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3404,7 +3404,6 @@ class inexact(number[_NBit1]): # type: ignore
34043404
def __getnewargs__(self: inexact[_64Bit]) -> tuple[float, ...]: ...
34053405

34063406
_IntType = TypeVar("_IntType", bound=integer[Any])
3407-
_FloatType = TypeVar('_FloatType', bound=floating[Any])
34083407

34093408
class floating(inexact[_NBit1]):
34103409
def __init__(self, value: _FloatValue = ..., /) -> None: ...
@@ -3834,27 +3833,30 @@ class busdaycalendar:
38343833
@property
38353834
def holidays(self) -> NDArray[datetime64]: ...
38363835

3837-
class finfo(Generic[_FloatType]):
3838-
dtype: dtype[_FloatType]
3839-
bits: int
3840-
eps: _FloatType
3841-
epsneg: _FloatType
3842-
iexp: int
3843-
machep: int
3844-
max: _FloatType
3845-
maxexp: int
3846-
min: _FloatType
3847-
minexp: int
3848-
negep: int
3849-
nexp: int
3850-
nmant: int
3851-
precision: int
3852-
resolution: _FloatType
3853-
smallest_subnormal: _FloatType
3836+
3837+
_FloatType_co = TypeVar('_FloatType_co', bound=floating[Any], covariant=True)
3838+
3839+
class finfo(Generic[_FloatType_co]):
3840+
dtype: Final[dtype[_FloatType_co]]
3841+
bits: Final[int]
3842+
eps: Final[_FloatType_co]
3843+
epsneg: Final[_FloatType_co]
3844+
iexp: Final[int]
3845+
machep: Final[int]
3846+
max: Final[_FloatType_co]
3847+
maxexp: Final[int]
3848+
min: Final[_FloatType_co]
3849+
minexp: Final[int]
3850+
negep: Final[int]
3851+
nexp: Final[int]
3852+
nmant: Final[int]
3853+
precision: Final[int]
3854+
resolution: Final[_FloatType_co]
3855+
smallest_subnormal: Final[_FloatType_co]
38543856
@property
3855-
def smallest_normal(self) -> _FloatType: ...
3857+
def smallest_normal(self) -> _FloatType_co: ...
38563858
@property
3857-
def tiny(self) -> _FloatType: ...
3859+
def tiny(self) -> _FloatType_co: ...
38583860
@overload
38593861
def __new__(
38603862
cls, dtype: inexact[_NBit1] | _DTypeLike[inexact[_NBit1]]
@@ -3868,18 +3870,22 @@ class finfo(Generic[_FloatType]):
38683870
cls, dtype: str
38693871
) -> finfo[floating[Any]]: ...
38703872

3871-
class iinfo(Generic[_IntType]):
3872-
dtype: dtype[_IntType]
3873-
kind: LiteralString
3874-
bits: int
3875-
key: LiteralString
3873+
_IntType_co = TypeVar("_IntType_co", bound=integer[Any], covariant=True)
3874+
3875+
class iinfo(Generic[_IntType_co]):
3876+
dtype: Final[dtype[_IntType_co]]
3877+
kind: Final[LiteralString]
3878+
bits: Final[int]
3879+
key: Final[LiteralString]
38763880
@property
38773881
def min(self) -> int: ...
38783882
@property
38793883
def max(self) -> int: ...
38803884

38813885
@overload
3882-
def __new__(cls, dtype: _IntType | _DTypeLike[_IntType]) -> iinfo[_IntType]: ...
3886+
def __new__(
3887+
cls, dtype: _IntType_co | _DTypeLike[_IntType_co]
3888+
) -> iinfo[_IntType_co]: ...
38833889
@overload
38843890
def __new__(cls, dtype: int | type[int]) -> iinfo[int_]: ...
38853891
@overload

0 commit comments

Comments
 (0)