Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Parser does not detect bound nonlocals when combining annotation and assignment #2115

Open
GeorchW opened this issue Aug 26, 2020 · 0 comments

Comments

@GeorchW
Copy link

GeorchW commented Aug 26, 2020

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?
@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Aug 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant