python-language-server icon indicating copy to clipboard operation
python-language-server copied to clipboard

SyntaxError: iterable unpacking cannot be used in comprehension

Open JacksonKearl opened this issue 5 years ago • 3 comments

Environment data

  • VS Code version: 1.45.0-insider
  • Extension version (available under the Extensions sidebar): 2020.4.74986
  • OS and version: MacOS Mojave
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.2, brew
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): none
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info microsoft/vscode-python#3977): either
  • Value of the python.languageServer setting: Microsoft

Expected behaviour

def foo():
    return ["bar", "baz"]

print([*foo() for _ in range(10)])

I would expect a red squiggle and syntax error to appear here, given at runtime it throws:

SyntaxError: iterable unpacking cannot be used in comprehension

Actual behaviour

image

JacksonKearl avatar Apr 27 '20 22:04 JacksonKearl

You will need a linter to catch these: image

karthiknadig avatar Apr 28 '20 01:04 karthiknadig

Many of the builtin linters don't flag this (bandit, pycodestyle, pydocstyle). And I don't think users (many of whom may be just starting out with python and not even know what a linter is) should need to install additional tooling to protect against basic syntax errors.

And in my case I am using flake8 but for whatever reason it didn't flag it either: image

Which means I had a very long running job fail at the last minute due to a syntax error.

JacksonKearl avatar Apr 28 '20 09:04 JacksonKearl

I now appear to be in a state where I have linting enabled in .vscode/settings.json, but when I run 'Python : Run Linting' nothing at all happens and there is nothing written to the python output channel. When I run 'Python: Enable Linting', it shows 'off' and even when I select 'on' and enter the quick pick again it remains 'off'

JacksonKearl avatar Apr 28 '20 10:04 JacksonKearl