Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NoReturn overloads from pow() #8568

Merged
merged 1 commit into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ class int:
@overload
def __pow__(self, __x: int, __modulo: None = ...) -> Any: ...
@overload
def __pow__(self, __x: int, __modulo: Literal[0]) -> NoReturn: ...
@overload
def __pow__(self, __x: int, __modulo: int) -> int: ...
def __rpow__(self, __x: int, __mod: int | None = ...) -> Any: ...
def __and__(self, __n: int) -> int: ...
Expand Down Expand Up @@ -1548,8 +1546,8 @@ _SupportsSomeKindOfPow = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs a
)

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

else:
@overload
def pow(__base: int, __exp: int, __mod: Literal[0]) -> NoReturn: ...
@overload
def pow(__base: int, __exp: int, __mod: int) -> int: ...
@overload
Expand Down
8 changes: 6 additions & 2 deletions test_cases/stdlib/builtins/test_pow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

from decimal import Decimal
from fractions import Fraction
from typing import Any, NoReturn
from typing import Any
from typing_extensions import Literal, assert_type

# See #7163
assert_type(pow(1, 0), Literal[1])
assert_type(1**0, Literal[1])
assert_type(pow(1, 0, None), Literal[1])

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

assert_type(pow(2, 4), int)
assert_type(2**4, int)
Expand Down