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

Pylance reports reportUnboundVariable when using walrus operator with conditional expressions and no brackets #381

Closed
charles-dexter-ward opened this issue Sep 17, 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

@charles-dexter-ward
Copy link

Environment data

  • Language Server version: 2020.9.5
  • OS and version: Windows 10
  • Python version: 3.8.5

Expected behaviour

The following snippet leads to a reportUnboundVariable on the items variable used in the for statement

 if items := result.get("Items", None) if result else None:
    for item in items:
        pass

The following snippets do not generate any reports

 if items := (result.get("Items", None) if result else None):
    for item in items:
        pass
 if items := result.get("Items", None):
    for item in items:
        pass

Actual behaviour

Usiing the walrus operator with a conditional expression which is not enclosed in parentheses leads to a reportUnboundVariable report

Code Snippet / Additional information

image

image

image

@erictraut
Copy link
Contributor

Thanks for the bug report.

When I initially added support for the walrus operator, I based my implementation on the draft specification. It appears that there was a change in the final specification that made it legal to use a ternary expression (X if Y else Z) in the right-hand side of the walrus operator.

I've updated the code to support the final spec, and the fix will be in the next version of Pylance.

@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 Sep 17, 2020
@github-actions github-actions bot removed the triage label Sep 17, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.9.6, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202096-23-september-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