Skip to content

Exponential operator results in typing.Any type #12073

Closed

Description

@isaacto

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

Activity

  1. JelleZijlstra commented on Jan 26, 2022

    @JelleZijlstra
    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.

  2. isaacto commented on Jan 27, 2022

    @isaacto
    Author

    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.

  3. JelleZijlstra commented on Jan 27, 2022

    @JelleZijlstra
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions