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

Undefined variable false positive with unreachable expression #452

Closed
hauntsaninja opened this issue Oct 3, 2020 · 2 comments
Closed

Undefined variable false positive with unreachable expression #452

hauntsaninja opened this issue Oct 3, 2020 · 2 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@hauntsaninja
Copy link

  • Language Server version: Pylance language server 2020.9.8 (pyright a0620921)
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8

Screen Shot 2020-10-03 at 12 36 40 AM

Expected behaviour

Pylance just complains about the unreachable (given my Python version) code

Actual behaviour

Pylance complains about message being undefined (in addition to the unreachable code)

Code Snippet / Additional information

import sys

def hello() -> None:
    message = "asdf"
    if sys.version_info < (3, 5) and message:
        print("hi")
@github-actions github-actions bot added the triage label Oct 3, 2020
@hauntsaninja hauntsaninja changed the title False positive for undefined variable with unreachable expresion Undefined variable false positive with unreachable expresion Oct 3, 2020
@hauntsaninja hauntsaninja changed the title Undefined variable false positive with unreachable expresion Undefined variable false positive with unreachable expression Oct 3, 2020
@erictraut
Copy link
Contributor

Thanks for the bug report. This was related to reachability analysis. The control flow node represented by message is provably never reachable within the function's body because the first part of the condition expression statically evaluates to False. This caused the analyzer to assume incorrectly that message was unbound.

I've added a fix, and it will be 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 labels Oct 3, 2020
@github-actions github-actions bot removed the triage label Oct 3, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.10.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#2020100-7-october-2020

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