Skip to content

builtins.pyi: Return complex from __(r)pow__() #2662

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

Merged
merged 3 commits into from
Dec 3, 2018

Conversation

utkarsh2102
Copy link
Contributor

This returns complex, instead of float.

Fixes #1406

@@ -196,15 +196,15 @@ 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) -> float: ...
def __pow__(self, x: float) -> complex: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should have an overload for when x is an int, since it will never be complex in that case. See #2444 for an example. Apart from that this PR looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. On it.

Copy link
Contributor Author

@utkarsh2102 utkarsh2102 Dec 1, 2018

Choose a reason for hiding this comment

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

Why is the CI failing now, @srittau? 😅
Would it be complex, instead of float?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It fails in mypy's test suite. It's likely the test suite needs to be adopted. I will have a closer look tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sure.
Didn't quite get it.

@utkarsh2102
Copy link
Contributor Author

Are these because of the changes I made?
image

srittau added a commit to srittau/mypy that referenced this pull request Dec 2, 2018
This is necessary due to python/typeshed#2662, where float.__pow__()
now returns complex in the general case.
@srittau
Copy link
Collaborator

srittau commented Dec 2, 2018

I started a discussion about the build failure in #1406.

This add a comment to the __pow__() function.

Fixes python#1406
@utkarsh2102
Copy link
Contributor Author

So basically, revert the changes the changes, no overload, just return float as before. But it would be helpful to add a comment to __pow__() that it returns complex if self is negative and x is not whole.

Done as asked.
Looks good, @srittau?

@srittau
Copy link
Collaborator

srittau commented Dec 3, 2018

Thank you for your persistence!

@srittau srittau merged commit bee236f into python:master Dec 3, 2018
@utkarsh2102 utkarsh2102 deleted the builtins-rpow branch December 3, 2018 21:57
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this pull request Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

float**float return type
2 participants