-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Improve stubs for __pow__
#6287
Changes from 5 commits
867bb7a
cdb959c
c9786cf
83b9b95
964511d
431741a
7c57a5a
a264b3f
226774a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,8 +221,12 @@ class int: | |
def __rmod__(self, __x: int) -> int: ... | ||
def __rdivmod__(self, __x: int) -> tuple[int, int]: ... | ||
@overload | ||
def __pow__(self, __x: int, __modulo: Literal[0]) -> NoReturn: ... | ||
@overload | ||
def __pow__(self, __x: Literal[2], __modulo: int | None = ...) -> int: ... | ||
@overload | ||
def __pow__(self, __x: Literal[3], __modulo: int | None = ...) -> int: ... | ||
@overload | ||
AlexWaygood marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def __pow__(self, __x: int, __modulo: int | None = ...) -> Any: ... # Return type can be int or float, depending on x. | ||
def __rpow__(self, __x: int, __mod: int | None = ...) -> Any: ... | ||
def __and__(self, __n: int) -> int: ... | ||
|
@@ -276,9 +280,10 @@ class float: | |
def __truediv__(self, __x: float) -> float: ... | ||
def __mod__(self, __x: float) -> float: ... | ||
def __divmod__(self, __x: float) -> tuple[float, float]: ... | ||
def __pow__( | ||
self, __x: float, __mod: None = ... | ||
) -> float: ... # In Python 3, returns complex if self is negative and x is not whole | ||
@overload | ||
def __pow__(self, __x: int, __mod: None = ...) -> float: ... | ||
@overload | ||
def __pow__(self, __x: float, __mod: None = ...) -> Any: ... # return type could be complex or float depending on x | ||
def __radd__(self, __x: float) -> float: ... | ||
def __rsub__(self, __x: float) -> float: ... | ||
def __rmul__(self, __x: float) -> float: ... | ||
|
@@ -324,12 +329,12 @@ class complex: | |
def __add__(self, __x: complex) -> complex: ... | ||
def __sub__(self, __x: complex) -> complex: ... | ||
def __mul__(self, __x: complex) -> complex: ... | ||
def __pow__(self, __x: complex, mod: None = ...) -> complex: ... | ||
def __pow__(self, __x: complex | int | float, mod: None = ...) -> complex: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
def __truediv__(self, __x: complex) -> complex: ... | ||
def __radd__(self, __x: complex) -> complex: ... | ||
def __rsub__(self, __x: complex) -> complex: ... | ||
def __rmul__(self, __x: complex) -> complex: ... | ||
def __rpow__(self, __x: complex, __mod: None = ...) -> complex: ... | ||
def __rpow__(self, __x: complex | int | float, __mod: None = ...) -> complex: ... | ||
def __rtruediv__(self, __x: complex) -> complex: ... | ||
def __eq__(self, __x: object) -> bool: ... | ||
def __ne__(self, __x: object) -> bool: ... | ||
|
@@ -1270,26 +1275,34 @@ class _SupportsPow3(Protocol[_E, _M, _T_co]): | |
def __pow__(self, __other: _E, __modulo: _M) -> _T_co: ... | ||
|
||
if sys.version_info >= (3, 8): | ||
@overload | ||
def pow(base: int, exp: int, mod: Literal[0]) -> NoReturn: ... | ||
@overload | ||
def pow(base: int, exp: int, mod: None = ...) -> Any: ... # returns int or float depending on whether exp is non-negative | ||
@overload | ||
def pow(base: int, exp: int, mod: int) -> int: ... | ||
@overload | ||
def pow(base: float, exp: float, mod: None = ...) -> float: ... | ||
def pow(base: float, exp: int, mod: None = ...) -> float: ... | ||
@overload | ||
def pow(base: float, exp: float, mod: None = ...) -> Any: ... # return type could be float or complex depending on x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. depending on exp There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It also depends on base. If the base is positive, then any power will also be positive. Complex numbers need a negative base and a negative power. Maybe the whole "depending on" part should be deleted? It obviously depends on the arguments in some way, which is really all that needs to be said. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's worth spelling out the conditions... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hah, sorry about that @hauntsaninja |
||
@overload | ||
def pow(base: _SupportsPow2[_E, _T_co], exp: _E) -> _T_co: ... | ||
@overload | ||
def pow(base: _SupportsPow3[_E, _M, _T_co], exp: _E, mod: _M) -> _T_co: ... | ||
|
||
else: | ||
@overload | ||
def pow(__base: Any, __exp: Any, __mod: Literal[0]) -> NoReturn: ... | ||
@overload | ||
def pow( | ||
__base: int, __exp: int, __mod: None = ... | ||
) -> Any: ... # returns int or float depending on whether exp is non-negative | ||
@overload | ||
def pow(__base: int, __exp: int, __mod: int) -> int: ... | ||
@overload | ||
def pow(__base: float, __exp: float, __mod: None = ...) -> float: ... | ||
def pow(__base: float, __exp: int, __mod: None = ...) -> float: ... | ||
@overload | ||
def pow(__base: float, __exp: float, __mod: None = ...) -> Any: ... # return type could be float or complex depending on x | ||
@overload | ||
def pow(__base: _SupportsPow2[_E, _T_co], __exp: _E) -> _T_co: ... | ||
@overload | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't result of x ** 0 == 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is
pow(1, 1, 0)
: