@@ -210,7 +210,7 @@ from typing import (
210
210
# library include `typing_extensions` stubs:
211
211
# https://github.com/python/typeshed/blob/main/stdlib/typing_extensions.pyi
212
212
from _typeshed import StrOrBytesPath , SupportsFlush , SupportsLenAndGetItem , SupportsWrite
213
- from typing_extensions import CapsuleType , Generic , LiteralString , Protocol , Self , TypeVar , overload
213
+ from typing_extensions import CapsuleType , Generic , LiteralString , Protocol , Self , TypeVar , deprecated , overload
214
214
215
215
from numpy import (
216
216
core ,
@@ -3410,22 +3410,27 @@ _ComplexValue: TypeAlias = (
3410
3410
| complex # `complex` is not a subtype of `SupportsComplex`
3411
3411
)
3412
3412
3413
- class integer (number [_NBit1 ]): # type: ignore
3413
+ @type_check_only
3414
+ class _Roundable :
3415
+ @overload
3416
+ def __round__ (self , / , ndigits : None = None ) -> int : ...
3417
+ @overload
3418
+ def __round__ (self , / , ndigits : SupportsIndex ) -> Self : ...
3419
+
3420
+ class integer (_Roundable , number [_NBit1 ]): # type: ignore
3414
3421
@property
3415
3422
def numerator (self ) -> Self : ...
3416
3423
@property
3417
3424
def denominator (self ) -> L [1 ]: ...
3418
- @overload
3419
- def __round__ (self , ndigits : None = ..., / ) -> int : ...
3420
- @overload
3421
- def __round__ (self , ndigits : SupportsIndex , / ) -> Self : ...
3425
+ def is_integer (self , / ) -> L [True ]: ...
3422
3426
3423
3427
def item (self , args : L [0 ] | tuple [()] | tuple [L [0 ]] = ..., / ) -> int : ...
3424
3428
def tolist (self ) -> int : ...
3425
- def is_integer (self ) -> L [True ]: ...
3426
- def bit_count (self ) -> int : ...
3427
- # NOTE: `__index__` is technically defined in the bottom-most sub-classes (`int64`, `uint32`, etc)
3428
- def __index__ (self ) -> int : ...
3429
+
3430
+ # NOTE: `bit_count` and `__index__` are technically defined in the concrete subtypes
3431
+ def bit_count (self , / ) -> int : ...
3432
+ def __index__ (self , / ) -> int : ...
3433
+
3429
3434
__truediv__ : _IntTrueDiv [_NBit1 ]
3430
3435
__rtruediv__ : _IntTrueDiv [_NBit1 ]
3431
3436
def __mod__ (self , value : _IntLike_co , / ) -> integer [Any ]: ...
@@ -3566,16 +3571,15 @@ class inexact(number[_NBit1]): ... # type: ignore[misc]
3566
3571
3567
3572
_IntType = TypeVar ("_IntType" , bound = integer [Any ])
3568
3573
3569
- class floating (inexact [_NBit1 ]):
3574
+ class floating (_Roundable , inexact [_NBit1 ]):
3570
3575
def __init__ (self , value : _FloatValue = ..., / ) -> None : ...
3571
3576
def item (self , args : L [0 ] | tuple [()] | tuple [L [0 ]] = ..., / ) -> float : ...
3572
3577
def tolist (self ) -> float : ...
3573
- def is_integer (self ) -> builtins .bool : ...
3574
- def as_integer_ratio (self ) -> tuple [int , int ]: ...
3575
- @overload
3576
- def __round__ (self , ndigits : None = ..., / ) -> int : ...
3577
- @overload
3578
- def __round__ (self , ndigits : SupportsIndex , / ) -> Self : ...
3578
+
3579
+ # NOTE: `is_integer` and `as_integer_ratio` are technically defined in the concrete subtypes
3580
+ def is_integer (self , / ) -> builtins .bool : ...
3581
+ def as_integer_ratio (self , / ) -> tuple [int , int ]: ...
3582
+
3579
3583
__add__ : _FloatOp [_NBit1 ]
3580
3584
__radd__ : _FloatOp [_NBit1 ]
3581
3585
__sub__ : _FloatOp [_NBit1 ]
@@ -3742,9 +3746,14 @@ class complexfloating(inexact[_NBit1], Generic[_NBit1, _NBit2]):
3742
3746
@property
3743
3747
def imag (self ) -> floating [_NBit2 ]: ... # type: ignore[override]
3744
3748
3745
- # NOTE: `__complex__` is not defined here, but in each of the concrete subtypes
3749
+ # NOTE: `__complex__` is technically defined in the concrete subtypes
3746
3750
def __complex__ (self , / ) -> complex : ...
3747
3751
def __abs__ (self , / ) -> floating [_NBit1 | _NBit2 ]: ... # type: ignore[override]
3752
+ @deprecated (
3753
+ "The Python built-in `round` is deprecated for complex scalars, and will raise a `TypeError` in a future release. "
3754
+ "Use `np.round` or `scalar.round` instead."
3755
+ )
3756
+ def __round__ (self , / , ndigits : SupportsIndex | None = None ) -> Self : ...
3748
3757
3749
3758
@overload
3750
3759
def __add__ (self , other : _Complex64_co , / ) -> complexfloating [_NBit1 , _NBit2 ]: ...
0 commit comments