Skip to content

Pow doesn't infer types when variables are used #16635

Closed
@GatienBouyer

Description

@GatienBouyer

Bug Report

I would expect that using variables to hold my values doesn't lose the resulting type.

Sample code:

my_wanted_int = 2 ** 3
reveal_type(my_wanted_int) # = int

my_2 = 2
my_3 = 3
reveal_type(my_2) # = int
reveal_type(my_3) # = int
star_result2 = my_2 ** my_3
reveal_type(star_result2) # = Any

Actual Behavior

$ mypy -V
mypy 1.7.1 (compiled: yes)
$ mypy -c "
my_wanted_int = 2 ** 3
reveal_type(my_wanted_int) # = int

my_2 = 2
my_3 = 3
reveal_type(my_2) # = int
reveal_type(my_3) # = int
star_result2 = my_2 ** my_3
reveal_type(star_result2) # = Any instead of int
"
<string>:3: note: Revealed type is "builtins.int"
<string>:7: note: Revealed type is "builtins.int"
<string>:8: note: Revealed type is "builtins.int"
<string>:10: note: Revealed type is "Any"
Success: no issues found in 1 source file

Here is the example in the mypy playground:
https://mypy-play.net/?mypy=latest&python=3.11&gist=e53d4334e01415845108453985c8f88f

Your Environment

  • Mypy version used: 1.7.1
  • Python version used: 3.11

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