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

Reveal Type and Hover Type inconsistency after type narrowing. #2024

Closed
hmc-cs-mdrissi opened this issue Nov 2, 2021 · 3 comments
Closed
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@hmc-cs-mdrissi
Copy link

hmc-cs-mdrissi commented Nov 2, 2021

Environment data

  • Language Server version: v2021.10.3
  • OS and version: Mac 11.6
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.8

Expected behaviour

reveal_type and hover type should always be same.

Actual behaviour

Somehow hovering over bottom x gives me a type of Unknown, but the reveal type is int.

Screen Shot 2021-11-02 at 1 29 18 PM

Code Snippet / Additional information

from typing import Optional


x: Optional[int] = None
for i in range(2):
    if i == 1:
        x = i

reveal_type(x)
assert x is not None
reveal_type(x)

I put this issue in pylance even though it's type checking related and maybe pyright is better because it's specifically hover type hint is off while reveal type hint is fine. This also seems weirdly specific to reveal_type as if I remove reveal_type here and make the code,

from typing import Optional


x: Optional[int] = None
for i in range(2):
    if i == 1:
        x = i

reveal_type(x)
assert x is not None
x

then hovering over bottom x shows expected type again.

Main reason I find hover being wrong in reveal type scenario an issue is original program this comes from was longer and x's hover type becomes incorrect after more logic outside of reveal type too. This is was first place I could track to where type started doing weird things.

@erictraut
Copy link
Contributor

Thanks for the bug report. I'm able to repro the problem. I've created a tracking bug in the pyright issue tracker.

@erictraut
Copy link
Contributor

This will be fixed in the next release.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Nov 2, 2021
@heejaechang
Copy link
Contributor

fixed in 2021.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants