pyright icon indicating copy to clipboard operation
pyright copied to clipboard

type from type checker is different to the type displayed on hover

Open DetachHead opened this issue 11 months ago • 1 comments

Describe the bug i have no idea what's going on here, i tried to minify it as best as i can. it seems that the type displayed in pyright's errors/notes here is different to the type that normally appears when you hover over the variable, even though they're both coming from pyright's language server.

Code or Screenshots

foo = None
bar = False
for _ in []:
    if not bar:
        continue
    if foo:
        reveal_type(foo) # reveal_type says int, vscode says Never
    baz = int(foo)
    foo = baz
    baz.asdf()

image

VS Code extension or command-line pyright vscode extension v1.1.353

i've disabled pylance and do not have any other extensions for python type checking installed, so this hover type is definitely coming from pyright as far as i'm aware

DetachHead avatar Mar 12 '24 10:03 DetachHead

I'm able to repro the problem, and I agree it's a bug. Type should be the same regardless of evaluation order, but there appears to be a bug that causes evaluation-order-dependent results in this case. I'll investigate further.

erictraut avatar Mar 13 '24 07:03 erictraut

This is addressed in pyright 1.1.364.

erictraut avatar May 22 '24 02:05 erictraut