Skip to content

Exponential operator results in typing.Any type #12073

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

Closed
isaacto opened this issue Jan 26, 2022 · 3 comments
Closed

Exponential operator results in typing.Any type #12073

isaacto opened this issue Jan 26, 2022 · 3 comments
Labels
bug mypy got something wrong

Comments

@isaacto
Copy link

isaacto commented Jan 26, 2022

Bug Report

A regression: in the current version of mypy, float exponential results in typing.Any. For int exponential it works, only float exponential fails.

(A clear and concise description of what the bug is.)

To Reproduce

$ cat test.py
reveal_type(2.0 ** 1.0)

Expected Behavior

It should say that the revealed type is builtins.float when run.

Actual Behavior

$ mypy test.py
test.py:1: note: Revealed type is "Any"

Your Environment

  • Mypy version used: 0.931
  • Mypy command-line flags: Nothing special.
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.9.5
  • Operating system and version: Ubuntu 20.04.3
@isaacto isaacto added the bug mypy got something wrong label Jan 26, 2022
@JelleZijlstra
Copy link
Member

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
Copy link
Author

isaacto commented 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
Copy link
Member

So why (-2) ** 0.5 should be of type float?

That does look like a mypy bug (it should be complex but mypy thinks it returns float). I'll report it over at typeshed.

why it can't simply say the return type is complex

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants