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
Exponential operator results in typing.Any type #12073
So why (-2) ** 0.5 should be of type float? And if this is the reason, why it can't simply say the return type is complex instead (which would easily tell the user what are the considerations)?
Personally I think the best user experience is for it to be simply a float, but it is just a preference.
Activity
JelleZijlstra commentedon Jan 26, 2022
You're hitting this case: https://github.com/python/typeshed/blob/98afaa4c76d4279846f278eb5be8b99c391e6a99/stdlib/builtins.pyi#L1348
This returns Any because it could be a complex.
isaacto commentedon Jan 27, 2022
So why (-2) ** 0.5 should be of type float? And if this is the reason, why it can't simply say the return type is complex instead (which would easily tell the user what are the considerations)?
Personally I think the best user experience is for it to be simply a float, but it is just a preference.
JelleZijlstra commentedon Jan 27, 2022
That does look like a mypy bug (it should be complex but mypy thinks it returns float). I'll report it over at typeshed.
A lot of users who expect floats will be very confused. Our general policy so far has been to return Any in cases like this.