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

Parser does not detect bound nonlocals when combining annotation and assignment

Open GeorchW opened this issue 5 years ago • 0 comments

The following snippet results in a spurious problem being reported when using the Microsoft language server. It does not occur in Jedi or Pylance.

def some_function():
    aLocalVariable: str = ""
    def an_inner_function():
        nonlocal aLocalVariable

When splitting the second line into two, like the following, it works:

    aLocalVariable: str
    aLocalVariable = ""

Expected behaviour

No problems reported.

Actual behaviour

The following problem is reported on the last line:

no binding for nonlocal 'aLocalVariable' foundPython(parser-16)

Steps to reproduce:

Paste the code from above into a python editor (don't even have to save).

Environment data

Environment data

  • VS Code version: 1.48.1
  • Extension version (available under the Extensions sidebar): v2020.8.103604
  • OS and version: Linux
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): none
  • Relevant/affected Python packages and their versions: none
  • Relevant/affected Python-related VS Code extensions and their versions: none
  • Value of the python.languageServer setting: Microsoft, and yes, it seems like it's fixed in Pylance. Is the Microsoft server deprecated or something?

GeorchW avatar Aug 26 '20 15:08 GeorchW