Skip to content

__pow__(float, float) should be float | complex, not Any #12895

Closed as not planned

Description

@vbraun

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.

Related issues:

Activity

  1. AlexWaygood commented on Oct 24, 2024

    @AlexWaygood
    Member

    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.

  2. Akuli commented on Oct 24, 2024

    @Akuli
    Collaborator

    Perhaps we could use float | Any.

  3. hauntsaninja commented on Oct 24, 2024

    @hauntsaninja
    Collaborator

    See #7682 (comment) , int | Any could be worth a shot

  4. embray commented on Oct 29, 2024

    @embray

    Most people most of the time are only using ** between two positive floats, so it's very confusing for those users

    I don't think we should be doing something wrong just because some users didn't learn basic maths

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions