Skip to content

Commit 303276a

Browse files
committed
TYP: Covariant iinfo & finfo type params, final attributes
1 parent 89b6820 commit 303276a

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

numpy/__init__.pyi

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,7 +3190,6 @@ class inexact(number[_NBit1]): # type: ignore
31903190
def __getnewargs__(self: inexact[_64Bit]) -> tuple[float, ...]: ...
31913191

31923192
_IntType = TypeVar("_IntType", bound=integer[Any])
3193-
_FloatType = TypeVar('_FloatType', bound=floating[Any])
31943193

31953194
class floating(inexact[_NBit1]):
31963195
def __init__(self, value: _FloatValue = ..., /) -> None: ...
@@ -3620,27 +3619,30 @@ class busdaycalendar:
36203619
@property
36213620
def holidays(self) -> NDArray[datetime64]: ...
36223621

3623-
class finfo(Generic[_FloatType]):
3624-
dtype: dtype[_FloatType]
3625-
bits: int
3626-
eps: _FloatType
3627-
epsneg: _FloatType
3628-
iexp: int
3629-
machep: int
3630-
max: _FloatType
3631-
maxexp: int
3632-
min: _FloatType
3633-
minexp: int
3634-
negep: int
3635-
nexp: int
3636-
nmant: int
3637-
precision: int
3638-
resolution: _FloatType
3639-
smallest_subnormal: _FloatType
3640-
@property
3641-
def smallest_normal(self) -> _FloatType: ...
3642-
@property
3643-
def tiny(self) -> _FloatType: ...
3622+
3623+
_FloatType_co = TypeVar('_FloatType_co', bound=floating[Any], covariant=True)
3624+
3625+
class finfo(Generic[_FloatType_co]):
3626+
dtype: Final[dtype[_FloatType_co]]
3627+
bits: Final[int]
3628+
eps: Final[_FloatType_co]
3629+
epsneg: Final[_FloatType_co]
3630+
iexp: Final[int]
3631+
machep: Final[int]
3632+
max: Final[_FloatType_co]
3633+
maxexp: Final[int]
3634+
min: Final[_FloatType_co]
3635+
minexp: Final[int]
3636+
negep: Final[int]
3637+
nexp: Final[int]
3638+
nmant: Final[int]
3639+
precision: Final[int]
3640+
resolution: Final[_FloatType_co]
3641+
smallest_subnormal: Final[_FloatType_co]
3642+
@property
3643+
def smallest_normal(self) -> _FloatType_co: ...
3644+
@property
3645+
def tiny(self) -> _FloatType_co: ...
36443646
@overload
36453647
def __new__(
36463648
cls, dtype: inexact[_NBit1] | _DTypeLike[inexact[_NBit1]]
@@ -3654,18 +3656,22 @@ class finfo(Generic[_FloatType]):
36543656
cls, dtype: str
36553657
) -> finfo[floating[Any]]: ...
36563658

3657-
class iinfo(Generic[_IntType]):
3658-
dtype: dtype[_IntType]
3659-
kind: LiteralString
3660-
bits: int
3661-
key: LiteralString
3659+
_IntType_co = TypeVar("_IntType_co", bound=integer[Any], covariant=True)
3660+
3661+
class iinfo(Generic[_IntType_co]):
3662+
dtype: Final[dtype[_IntType_co]]
3663+
kind: Final[LiteralString]
3664+
bits: Final[int]
3665+
key: Final[LiteralString]
36623666
@property
36633667
def min(self) -> int: ...
36643668
@property
36653669
def max(self) -> int: ...
36663670

36673671
@overload
3668-
def __new__(cls, dtype: _IntType | _DTypeLike[_IntType]) -> iinfo[_IntType]: ...
3672+
def __new__(
3673+
cls, dtype: _IntType_co | _DTypeLike[_IntType_co]
3674+
) -> iinfo[_IntType_co]: ...
36693675
@overload
36703676
def __new__(cls, dtype: int | type[int]) -> iinfo[int_]: ...
36713677
@overload

0 commit comments

Comments
 (0)