-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
float**float return type #1406
Comments
Making it |
__pow__ will return a float or complex value, depending on the input values. While float is a subtype of complex, it will be inconvenient for callers to handle a complex return value. Closes python#1406
I would also slightly prefer returning |
__rpow__() Fixes python#1406
PR #2662, which implements this, causes CI to fail, due to problems with the sample code copied from the standard lib's |
I still did not understand the reason for CI failure :/ |
Returning |
Ah, okay. |
I would be unhappy if we changed this to For the similar case of I expect it would be hugely inconvenient if e.g. |
This makes sense. |
Why not leave well enough alone? If someone uses |
As far as I understand, in #2662, I think there should only be an overload for when |
I am a bit conflicted on this issue. On the one hand, returning So basically, revert the changes the changes, no overload, just return |
Also, in my ongoing effort to promote |
Sure, on it. |
This add a comment to the __pow__() function. Fixes python#1406
float**float is currently defined as returning float, but in Python 3, (negative float) ** (non-whole float) returns a complex number. (In Python 2 it raises ValueError.)
I'm not sure what to do about this -- in mypy a plugin won't be very effective, because typically the sign of the base (left operand) is not known statically (as opposed to the exponent, which is often a literal, which is how we addressed this for int**(negative int)).
Declaring the result a complex is technically correct (since float is effectively a subclass of complex, just like int is effectively a subclass of float), but probably going to be a pain. Making it Union[float, complex] is likely worse. Keeping it float is a lie and may lead to unanticipated errors, and making it Any (like we do for int**int when we don't know the sign of the exponent) a cop-out that just hides more errors.
All in all I think we should change this to complex, even if it's a pain. Any other opinions?
The text was updated successfully, but these errors were encountered: