@@ -221,9 +221,13 @@ class int:
221
221
def __rmod__ (self , __x : int ) -> int : ...
222
222
def __rdivmod__ (self , __x : int ) -> tuple [int , int ]: ...
223
223
@overload
224
- def __pow__ (self , __x : Literal [ 2 ] , __modulo : int | None = ... ) -> int : ...
224
+ def __pow__ (self , __x : int , __modulo : Literal [ 0 ] ) -> NoReturn : ...
225
225
@overload
226
- def __pow__ (self , __x : int , __modulo : int | None = ...) -> Any : ... # Return type can be int or float, depending on x.
226
+ def __pow__ (self , __x : Literal [2 , 3 , 4 , 5 ], __modulo : int | None = ...) -> int : ...
227
+ # positive x -> int; negative x -> float
228
+ # return type must be Any as `int | float` causes too many false-positive errors
229
+ @overload
230
+ def __pow__ (self , __x : int , __modulo : int | None = ...) -> Any : ...
227
231
def __rpow__ (self , __x : int , __mod : int | None = ...) -> Any : ...
228
232
def __and__ (self , __n : int ) -> int : ...
229
233
def __or__ (self , __n : int ) -> int : ...
@@ -276,9 +280,12 @@ class float:
276
280
def __truediv__ (self , __x : float ) -> float : ...
277
281
def __mod__ (self , __x : float ) -> float : ...
278
282
def __divmod__ (self , __x : float ) -> tuple [float , float ]: ...
279
- def __pow__ (
280
- self , __x : float , __mod : None = ...
281
- ) -> float : ... # In Python 3, returns complex if self is negative and x is not whole
283
+ @overload
284
+ def __pow__ (self , __x : int , __mod : None = ...) -> float : ...
285
+ # positive x -> float; negative x -> complex
286
+ # return type must be Any as `float | complex` causes too many false-positive errors
287
+ @overload
288
+ def __pow__ (self , __x : float , __mod : None = ...) -> Any : ...
282
289
def __radd__ (self , __x : float ) -> float : ...
283
290
def __rsub__ (self , __x : float ) -> float : ...
284
291
def __rmul__ (self , __x : float ) -> float : ...
@@ -1271,25 +1278,35 @@ class _SupportsPow3(Protocol[_E, _M, _T_co]):
1271
1278
1272
1279
if sys .version_info >= (3 , 8 ):
1273
1280
@overload
1274
- def pow (base : int , exp : int , mod : None = ...) -> Any : ... # returns int or float depending on whether exp is non-negative
1281
+ def pow (base : int , exp : int , mod : Literal [0 ]) -> NoReturn : ...
1282
+ # int base & positive-int exp -> int; int base & negative-int exp -> float
1283
+ # return type must be Any as `int | float` causes too many false-positive errors
1284
+ @overload
1285
+ def pow (base : int , exp : int , mod : None = ...) -> Any : ...
1275
1286
@overload
1276
1287
def pow (base : int , exp : int , mod : int ) -> int : ...
1277
1288
@overload
1278
- def pow (base : float , exp : float , mod : None = ...) -> float : ...
1289
+ def pow (base : float , exp : int , mod : None = ...) -> float : ...
1290
+ # float base & float exp could return float or complex
1291
+ # return type must be Any as `float | complex` causes too many false-positive errors
1292
+ @overload
1293
+ def pow (base : float , exp : float , mod : None = ...) -> Any : ...
1279
1294
@overload
1280
1295
def pow (base : _SupportsPow2 [_E , _T_co ], exp : _E ) -> _T_co : ...
1281
1296
@overload
1282
1297
def pow (base : _SupportsPow3 [_E , _M , _T_co ], exp : _E , mod : _M ) -> _T_co : ...
1283
1298
1284
1299
else :
1285
1300
@overload
1286
- def pow (
1287
- __base : int , __exp : int , __mod : None = ...
1288
- ) -> Any : ... # returns int or float depending on whether exp is non-negative
1301
+ def pow (__base : int , __exp : int , __mod : Literal [ 0 ]) -> NoReturn : ...
1302
+ @ overload
1303
+ def pow ( __base : int , __exp : int , __mod : None = ...) -> Any : ...
1289
1304
@overload
1290
1305
def pow (__base : int , __exp : int , __mod : int ) -> int : ...
1291
1306
@overload
1292
- def pow (__base : float , __exp : float , __mod : None = ...) -> float : ...
1307
+ def pow (__base : float , __exp : int , __mod : None = ...) -> float : ...
1308
+ @overload
1309
+ def pow (__base : float , __exp : float , __mod : None = ...) -> Any : ...
1293
1310
@overload
1294
1311
def pow (__base : _SupportsPow2 [_E , _T_co ], __exp : _E ) -> _T_co : ...
1295
1312
@overload
0 commit comments