Skip to content
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

pow float return value is Any in 0.950 #7733

Closed
TylerYep opened this issue Apr 28, 2022 · 3 comments · Fixed by #7737
Closed

pow float return value is Any in 0.950 #7733

TylerYep opened this issue Apr 28, 2022 · 3 comments · Fixed by #7737

Comments

@TylerYep
Copy link

TylerYep commented Apr 28, 2022

Bug Report

I upgraded to mypy 0.950 today and ran into the following error involving function return types:

To Reproduce

# x.py
def fn(x: float = 8.9) -> float:
    return 2 ** x    # error: Returning Any from function declared to return "float"  [no-any-return]

Expected Behavior

Expected this to pass cleanly.

Actual Behavior

I'm not sure why this now returns Any.

Your Environment

  • Mypy version used: 0.950
  • Mypy configuration options from mypy.ini (and other config files): strict = True
  • Python version used: Python 3.10.0
  • Operating system and version: Mac OSX
@TylerYep TylerYep added the bug label Apr 28, 2022
@TylerYep

This comment was marked as off-topic.

@TylerYep TylerYep changed the title pow float return value is Any? Incompatible return types (Any, object) Apr 28, 2022
@TylerYep TylerYep changed the title Incompatible return types (Any, object) Incompatible return types (Any, object) errors in 0.950 Apr 28, 2022
@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 28, 2022

Could you open a separate issue about the second thing? It looks like a completely different problem.

Issue number 1 looks like a pretty clear consequence of #7047 (cc. @JelleZijlstra). We might be able to make the types more specific by adding yet another overload to int.__pow__ or float.__rpow__. I can create a PR in the morning.

@TylerYep TylerYep changed the title Incompatible return types (Any, object) errors in 0.950 pow float return value is Any in 0.950 Apr 28, 2022
@JelleZijlstra JelleZijlstra transferred this issue from python/mypy Apr 28, 2022
@Akuli
Copy link
Collaborator

Akuli commented Apr 28, 2022

int ** float can be a complex number, if the int is negative.

>>> (-1) ** 2.3
(0.587785252292474+0.8090169943749468j)

But this doesn't happen for 2 ** float, or for any other positive number instead of 2:

>>> 2 ** (-3.4)
0.09473228540689989

0 ** float behaves a bit surprisingly, and I don't think we should handle it specially in the stubs. In practice, the 0 is very unlikely to be specified in a way where the type checker can infer its type to be Literal[0].

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

Successfully merging a pull request may close this issue.

3 participants