Skip to content

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

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
vbraun opened this issue Oct 24, 2024 · 4 comments
Closed

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

vbraun opened this issue Oct 24, 2024 · 4 comments

Comments

@vbraun
Copy link

vbraun commented Oct 24, 2024

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:

@AlexWaygood
Copy link
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.

@srittau srittau closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2024
@Akuli
Copy link
Collaborator

Akuli commented Oct 24, 2024

Perhaps we could use float | Any.

@hauntsaninja
Copy link
Collaborator

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

@embray
Copy link

embray commented Oct 29, 2024

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants