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

Recognize missing brackets for assignment expression #1838

Closed
cdce8p opened this issue Sep 20, 2021 · 2 comments
Closed

Recognize missing brackets for assignment expression #1838

cdce8p opened this issue Sep 20, 2021 · 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

@cdce8p
Copy link

cdce8p commented Sep 20, 2021

It would be nice if Pylance could recognize that the example below would result in a SyntaxError.

l = lambda s: val if val := s.capitalize() else None
$ python test.py
  File "/.../test.py", line 1
    l = lambda s: val if val := s.capitalize() else None
                  ^^^^^^^^^^
SyntaxError: expected 'else' after 'if' expression

--
To be valid, brackets around the assignment expression are necessary. This only applies to if expressions. Normal if statements will work, even without them.

l = lambda s: val if (val := s.capitalize()) else None

--
Tested with Pylance: v2021.9.2

@erictraut
Copy link
Contributor

Thanks for the bug report. There was indeed a bug in pyright's parser that resulted in a false negative in this case. The fix 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 and removed triage labels Sep 20, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.9.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202193-22-september-2021

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