Skip to content

Commit 8a326dc

Browse files
authored
Remove NoReturn overloads from pow() (#8568)
1 parent 0428069 commit 8a326dc

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

stdlib/builtins.pyi

+2-6
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ class int:
266266
@overload
267267
def __pow__(self, __x: int, __modulo: None = ...) -> Any: ...
268268
@overload
269-
def __pow__(self, __x: int, __modulo: Literal[0]) -> NoReturn: ...
270-
@overload
271269
def __pow__(self, __x: int, __modulo: int) -> int: ...
272270
def __rpow__(self, __x: int, __mod: int | None = ...) -> Any: ...
273271
def __and__(self, __n: int) -> int: ...
@@ -1548,8 +1546,8 @@ _SupportsSomeKindOfPow = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs a
15481546
)
15491547

15501548
if sys.version_info >= (3, 8):
1551-
@overload
1552-
def pow(base: int, exp: int, mod: Literal[0]) -> NoReturn: ...
1549+
# TODO: `pow(int, int, Literal[0])` fails at runtime,
1550+
# but adding a `NoReturn` overload isn't a good solution for expressing that (see #8566).
15531551
@overload
15541552
def pow(base: int, exp: int, mod: int) -> int: ...
15551553
@overload
@@ -1587,8 +1585,6 @@ if sys.version_info >= (3, 8):
15871585
def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = ...) -> complex: ...
15881586

15891587
else:
1590-
@overload
1591-
def pow(__base: int, __exp: int, __mod: Literal[0]) -> NoReturn: ...
15921588
@overload
15931589
def pow(__base: int, __exp: int, __mod: int) -> int: ...
15941590
@overload

test_cases/stdlib/builtins/test_pow.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
from decimal import Decimal
44
from fractions import Fraction
5-
from typing import Any, NoReturn
5+
from typing import Any
66
from typing_extensions import Literal, assert_type
77

88
# See #7163
99
assert_type(pow(1, 0), Literal[1])
1010
assert_type(1**0, Literal[1])
1111
assert_type(pow(1, 0, None), Literal[1])
1212

13-
assert_type(pow(2, 4, 0), NoReturn)
13+
# TODO: We don't have a good way of expressing the fact
14+
# that passing 0 for the third argument will lead to an exception being raised
15+
# (see discussion in #8566)
16+
#
17+
# assert_type(pow(2, 4, 0), NoReturn)
1418

1519
assert_type(pow(2, 4), int)
1620
assert_type(2**4, int)

0 commit comments

Comments
 (0)