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 fails to parse walrus operator inside of list comprehension condition inside of decorator argument list #1745

Closed
Jordan-Cottle opened this issue Sep 1, 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

@Jordan-Cottle
Copy link

Jordan-Cottle commented Sep 1, 2021

Environment data

  • Language Server version: 2021.8.3
  • OS and version: linux x64
  • Python version (and distribution if applicable, e.g. Anaconda): Python 3.8.10
  • python.analysis.indexing: undefined
  • python.analysis.typeCheckingMode: off

Expected behaviour

Pylance should be able to parse changes in my file properly.

Actual behavior

Pylance reports the error below at the top of the file.

An internal error occurred while binding file "/home/jdcottle/discommand/tests/models/test_user.py": TypeError: Cannot read property 'lookUpSymbol' of undefined
    at b._bindNameToScope (/home/jdcottle/.vscode-server/extensions/ms-python.vscode-pylance-2021.8.3/dist/pyright-internal/src/analyzer/binder.ts:2928:32)
    at b.visitAssignmentExpression (/home/jdcottle/.vscode-server/extensions/ms-python.vscode-pylance-2021.8.3/dist/pyright-internal/src/analyzer/binder.ts:842:18)
    at b.visitNode (/home/jdcottle/.vscode-server/extensions/ms-python.vscode-pylance-2021.8.3/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:136:26)
    at b.walk (/home/jdcottle/.vscode-server/extensions/ms-python.vscode-pylance-2021.8.3/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:96:37)
    at callback (/home/jdcottle/.vscode-server/extensions/ms-python.vscode-pylance-2021.8.3/dist/pyright-internal/src/analyzer/binder.ts:1806:22)
    at b._setTrueFalseTargets (/home/jdcottle/.vscode-server/extensions/ms-python.vscode-pylance-2021.8.3/dist/pyright-internal/src/analyzer/binder.ts:2432:9)
    at b._disableTrueFalseTargets (/home/jdcottle/.vscode-server/extensions/ms-python.vscode-pylance-2021.8.3/dist/pyright-internal/src/analyzer/binder.ts:2419:14)
    at b.visitBinaryOperation (/home/jdcottle/.vscode-server/extensions/ms-python.vscode-pylance-2021.8.3/dist/pyright-internal/src/analyzer/binder.ts:1804:18)
    at b.visitNode (/home/jdcottle/.vscode-server/extensions/ms-python.vscode-pylance-2021.8.3/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:154:26)
    at b.walk (/home/jdcottle/.vscode-server/extensions/ms-python.vscode-pylance-2021.8.3/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:96:37)

Additionally pylance reports a bunch of random errors throughout the rest of the file. Every line of code that isn't at the module level gets flagged as unreachable, and every non-module-level identifier reference is marked as not defined.

Logs

Python Language Server Log
https://pastebin.com/2G2nPLPh

Code Snippet / Additional information

This specific diff breaks pylance parsing. The file before was parsed properly, but after this change pylance throws the error and reports a bunch of nonsense errors.

I suspect the walrus operator inside of the list comprehension, inside of the decorator argument list is causing some kind of problem with whatever is trying to parse/make sense of this. This code generates over 8000 tests, so I definitely won't be keeping it.

@pytest.mark.parametrize(
    "set_flags",
    [
        flag_combination
        for i in range(1, len(UserFlag))
        for combination in combinations(UserFlag, i)
        if UserFlag.NONE not in (flag_combination := set(combination))
    ],
)

If you have poetry set up, you can clone the project and run the tests to demonstrate that it parses and runs as valid python.

git clone git@github.com:Jordan-Cottle/discommand.git
cd discommand/
git checkout break-pylance
poetry install
pytest

Example test output below

$ pytest
=========================================================================================================================== test session starts ============================================================================================================================
platform linux -- Python 3.8.10, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /home/jdcottle/discommand/.venv/bin/python
cachedir: .pytest_cache
rootdir: /home/jdcottle/test/discommand, configfile: pyproject.toml, testpaths: tests
plugins: cov-2.12.1
collected 8218 items                                                                                                                                                                                                                                                       
stepwise: no previously failed tests, not skipping.

... (Lots of passing tests)

---------- coverage: platform linux, python 3.8.10-final-0 -----------
Name                                   Stmts   Miss  Cover   Missing
--------------------------------------------------------------------
discommand/models/common.py               43      4    91%   33, 37-38, 41
discommand/models/user.py                 45      2    96%   44-45
discommand/models/interactions.py         36      0   100%
discommand/models/command.py              56      0   100%
discommand/models/__init__.py              4      0   100%
discommand/constants/user.py              21      0   100%
discommand/constants/interactions.py      12      0   100%
discommand/constants/common.py             8      0   100%
discommand/constants/command.py           17      0   100%
discommand/constants/__init__.py           2      0   100%
discommand/__init__.py                     3      0   100%
--------------------------------------------------------------------
TOTAL                                    247      6    98%

FAIL Required test coverage of 100.0% not reached. Total coverage: 97.57%

========================================================================================================================== 8218 passed in 19.69s ===========================================================================================================================
@github-actions github-actions bot added the triage label Sep 1, 2021
@erictraut
Copy link
Contributor

Thanks for reporting the bug. This will be fixed 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 1, 2021
@jakebailey
Copy link
Member

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