You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
__pow__(float, float) should be float | complex, not Any #12895
Exponentiating a float with fractional power can be float or a complex, but nothing else:
In [1]: 1.0 ** 0.5
Out[1]: 1.0
In [2]: (-1.0) ** 0.5
Out[2]: (6.123233995736766e-17+1j)
But the result is currently typed as Any, but float | complex would be stricter and more self-explanatory
I don't see any technical reason for not doing so, maybe I'm missing something? But getting Any and then have mypy --strict complain about it is definitely a headscratcher.
We've tried this before, and it causes too many false positive errors unfortunately. Most people most of the time are only using ** between two positive floats, so it's very confusing for those users to find that mypy infers the result as float | complex when they know it's a float at runtime. You can see some discussion in #7682.
Activity
AlexWaygood commentedon Oct 24, 2024
We've tried this before, and it causes too many false positive errors unfortunately. Most people most of the time are only using
**between two positive floats, so it's very confusing for those users to find that mypy infers the result asfloat | complexwhen they know it's afloatat runtime. You can see some discussion in #7682.Akuli commentedon Oct 24, 2024
Perhaps we could use
float | Any.hauntsaninja commentedon Oct 24, 2024
See #7682 (comment) , int | Any could be worth a shot
embray commentedon Oct 29, 2024
I don't think we should be doing something wrong just because some users didn't learn basic maths