Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit83e4e7f

Browse files
authored
Merge pull request#28966 from charris/backport-28958
TYP: reject complex scalar types in ndarray.__ifloordiv__
2 parents6c42775 +248f0cb commit83e4e7f

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

‎numpy/__init__.pyi

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,6 +3356,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
33563356
@overload
33573357
def__iadd__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
33583358

3359+
#
33593360
@overload
33603361
def__isub__(
33613362
self:NDArray[unsignedinteger[Any]],
@@ -3379,6 +3380,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
33793380
@overload
33803381
def__isub__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
33813382

3383+
#
33823384
@overload
33833385
def__imul__(self:NDArray[np.bool],other:_ArrayLikeBool_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
33843386
@overload
@@ -3403,66 +3405,51 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
34033405
def__imul__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
34043406

34053407
@overload
3406-
def__itruediv__(self:NDArray[float64],other:_ArrayLikeFloat_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
3407-
@overload
3408-
def__itruediv__(self:NDArray[floating[Any]],other:_ArrayLikeFloat_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
3409-
@overload
3410-
def__itruediv__(self:NDArray[complex128],other:_ArrayLikeComplex_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
3411-
@overload
3412-
def__itruediv__(
3413-
self:NDArray[complexfloating[Any]],
3414-
other:_ArrayLikeComplex_co,
3408+
def__ipow__(
3409+
self:NDArray[unsignedinteger[Any]],
3410+
other:_ArrayLikeUInt_co|_IntLike_co,
34153411
/,
34163412
)->ndarray[_ShapeT_co,_DType_co]: ...
34173413
@overload
3418-
def__itruediv__(self:NDArray[timedelta64],other:_ArrayLikeInt,/)->ndarray[_ShapeT_co,_DType_co]: ...
3414+
def__ipow__(self:NDArray[signedinteger[Any]],other:_ArrayLikeInt_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
34193415
@overload
3420-
def__itruediv__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
3421-
3416+
def__ipow__(self:NDArray[float64],other:_ArrayLikeFloat_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
34223417
@overload
3423-
def__ifloordiv__(
3424-
self:NDArray[unsignedinteger[Any]],
3425-
other:_ArrayLikeUInt_co|_IntLike_co,
3426-
/,
3427-
)->ndarray[_ShapeT_co,_DType_co]: ...
3418+
def__ipow__(self:NDArray[floating[Any]],other:_ArrayLikeFloat_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
34283419
@overload
3429-
def__ifloordiv__(self:NDArray[signedinteger[Any]],other:_ArrayLikeInt_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
3420+
def__ipow__(self:NDArray[complex128],other:_ArrayLikeComplex_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
34303421
@overload
3431-
def__ifloordiv__(self:NDArray[float64],other:_ArrayLikeFloat_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
3422+
def__ipow__(self:NDArray[complexfloating[Any]],other:_ArrayLikeComplex_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
34323423
@overload
3433-
def__ifloordiv__(self:NDArray[floating[Any]],other:_ArrayLikeFloat_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
3424+
def__ipow__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
3425+
3426+
#
34343427
@overload
3435-
def__ifloordiv__(self:NDArray[complex128],other:_ArrayLikeComplex_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
3428+
def__itruediv__(self:NDArray[floating],other:_ArrayLikeFloat_co,/)->ndarray[_ShapeT_co,_DTypeT_co]: ...
34363429
@overload
3437-
def__ifloordiv__(
3438-
self:NDArray[complexfloating[Any]],
3439-
other:_ArrayLikeComplex_co,
3440-
/,
3441-
)->ndarray[_ShapeT_co,_DType_co]: ...
3430+
def__itruediv__(self:NDArray[complexfloating],other:_ArrayLikeComplex_co,/)->ndarray[_ShapeT_co,_DTypeT_co]: ...
34423431
@overload
3443-
def__ifloordiv__(self:NDArray[timedelta64],other:_ArrayLikeInt,/)->ndarray[_ShapeT_co,_DType_co]: ...
3432+
def__itruediv__(self:NDArray[timedelta64],other:_ArrayLikeInt,/)->ndarray[_ShapeT_co,_DTypeT_co]: ...
34443433
@overload
3445-
def__ifloordiv__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
3434+
def__itruediv__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DTypeT_co]: ...
34463435

3436+
# keep in sync with `__imod__`
34473437
@overload
3448-
def__ipow__(
3449-
self:NDArray[unsignedinteger[Any]],
3438+
def__ifloordiv__(
3439+
self:NDArray[unsignedinteger],
34503440
other:_ArrayLikeUInt_co|_IntLike_co,
3451-
/,
3452-
)->ndarray[_ShapeT_co,_DType_co]: ...
3441+
/
3442+
)->ndarray[_ShapeT_co,_DTypeT_co]: ...
34533443
@overload
3454-
def__ipow__(self:NDArray[signedinteger[Any]],other:_ArrayLikeInt_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
3455-
@overload
3456-
def__ipow__(self:NDArray[float64],other:_ArrayLikeFloat_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
3457-
@overload
3458-
def__ipow__(self:NDArray[floating[Any]],other:_ArrayLikeFloat_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
3444+
def__ifloordiv__(self:NDArray[signedinteger],other:_ArrayLikeInt_co,/)->ndarray[_ShapeT_co,_DTypeT_co]: ...
34593445
@overload
3460-
def__ipow__(self:NDArray[complex128],other:_ArrayLikeComplex_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
3446+
def__ifloordiv__(self:NDArray[floating],other:_ArrayLikeFloat_co,/)->ndarray[_ShapeT_co,_DTypeT_co]: ...
34613447
@overload
3462-
def__ipow__(self:NDArray[complexfloating[Any]],other:_ArrayLikeComplex_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
3448+
def__ifloordiv__(self:NDArray[timedelta64],other:_ArrayLikeInt,/)->ndarray[_ShapeT_co,_DTypeT_co]: ...
34633449
@overload
3464-
def__ipow__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
3450+
def__ifloordiv__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DTypeT_co]: ...
34653451

3452+
# keep in sync with `__ifloordiv__`
34663453
@overload
34673454
def__imod__(
34683455
self:NDArray[unsignedinteger[Any]],
@@ -3484,6 +3471,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
34843471
@overload
34853472
def__imod__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
34863473

3474+
# keep in sync with `__irshift__`
34873475
@overload
34883476
def__ilshift__(
34893477
self:NDArray[unsignedinteger[Any]],
@@ -3495,6 +3483,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
34953483
@overload
34963484
def__ilshift__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
34973485

3486+
# keep in sync with `__ilshift__`
34983487
@overload
34993488
def__irshift__(
35003489
self:NDArray[unsignedinteger[Any]],
@@ -3506,6 +3495,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
35063495
@overload
35073496
def__irshift__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
35083497

3498+
# keep in sync with `__ixor__` and `__ior__`
35093499
@overload
35103500
def__iand__(self:NDArray[np.bool],other:_ArrayLikeBool_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
35113501
@overload
@@ -3519,6 +3509,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
35193509
@overload
35203510
def__iand__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
35213511

3512+
# keep in sync with `__iand__` and `__ior__`
35223513
@overload
35233514
def__ixor__(self:NDArray[np.bool],other:_ArrayLikeBool_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
35243515
@overload
@@ -3532,6 +3523,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
35323523
@overload
35333524
def__ixor__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
35343525

3526+
# keep in sync with `__iand__` and `__ixor__`
35353527
@overload
35363528
def__ior__(self:NDArray[np.bool],other:_ArrayLikeBool_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
35373529
@overload
@@ -3545,6 +3537,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
35453537
@overload
35463538
def__ior__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
35473539

3540+
#
35483541
@overload
35493542
def__imatmul__(self:NDArray[np.bool],other:_ArrayLikeBool_co,/)->ndarray[_ShapeT_co,_DType_co]: ...
35503543
@overload
@@ -3562,6 +3555,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
35623555
@overload
35633556
def__imatmul__(self:NDArray[object_],other:Any,/)->ndarray[_ShapeT_co,_DType_co]: ...
35643557

3558+
#
35653559
def__dlpack__(
35663560
self:NDArray[number[Any]],
35673561
/,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ AR_i // AR_LIKE_m # E: Unsupported operand types
7272
AR_f//AR_LIKE_m# E: Unsupported operand types
7373
AR_c//AR_LIKE_m# E: Unsupported operand types
7474

75+
# regression tests for https://github.com/numpy/numpy/issues/28957
76+
AR_c//2# type: ignore[operator]
77+
AR_c//AR_i# type: ignore[operator]
78+
AR_c//AR_c# type: ignore[operator]
79+
7580
# Array multiplication
7681

7782
AR_b*=AR_LIKE_u# E: incompatible type

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp