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

Improve stubs for __pow__ #6287

Merged
merged 9 commits into from
Nov 12, 2021
Merged
Changes from 1 commit
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: 4 additions & 4 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ class float:
@overload
def __pow__(self, __x: int, __mod: None = ...) -> float: ...
@overload
def __pow__(self, __x: float, __mod: None = ...) -> Any: ...
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: ...
def __rfloordiv__(self, __x: float) -> float: ...
def __rtruediv__(self, __x: float) -> float: ...
def __rmod__(self, __x: float) -> float: ...
def __rdivmod__(self, __x: float) -> tuple[float, float]: ...
def __rpow__(self, __x: float, __mod: None = ...) -> Any: ...
def __rpow__(self, __x: float, __mod: None = ...) -> float: ...
def __getnewargs__(self) -> tuple[float]: ...
def __trunc__(self) -> int: ...
if sys.version_info >= (3, 9):
Expand Down Expand Up @@ -1284,7 +1284,7 @@ if sys.version_info >= (3, 8):
@overload
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
def pow(base: float, exp: float, mod: None = ...) -> Any: ... # return type could be float or complex depending on x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depending on exp

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth spelling out the conditions... pow is like catnip for typeshed contributors, because everyone always starts off thinking only about positive integers :-)

Copy link
Member Author

Choose a reason for hiding this comment

The 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
Expand All @@ -1302,7 +1302,7 @@ else:
@overload
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
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
Expand Down