Issue with type-narrowing inside while loop #3236
Labels
addressed in next version
Issue is fixed and will appear in next published version
bug
Something isn't working
Describe the bug
Pyright seemingly resets type-narrowing in specific circumstances. however adding boilerplate code fixes this?
To Reproduce
See the Screenshots/Code section below.
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots or Code
With the original code:
Pyright outputs the following:
Moving the
None
check inside the loopPyright outputs the following
adding a
reveal_type
aboveif v is None:
Pyright outputs the following
why does adding
reveal_type
here cause this to type-check???VS Code extension or command-line
pyright 1.1.231
Additional context
mypy, once remoiving reliance on
Self
since it is currently unsupported for the original snippet outputs the followingwhich is what I would expect pyright to do.
Interesting tidbit
When using pylance (v2022.3.3-pre.1) moving the position of the cursor and saving will randomly cause the file to pass/fail type-checking. Not sure what to make of that.
Code_HPU5zYAuZ4.mp4
Would it be wise to make an issue on the pylance repo for this?
The text was updated successfully, but these errors were encountered: