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

Incorrect marking of Expected expression when unpacking tuple and using type annotations #700

Closed
alvesvaren opened this issue Dec 8, 2020 · 4 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

@alvesvaren
Copy link

alvesvaren commented Dec 8, 2020

Environment data

  • Language Server version: v2020.12.0
  • OS and version: Arch Linux 5.9.12-arch1-1
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.9.0

Expected behaviour

data: Tuple[List[str], ...] = *map(example),

works fine without any problems with Pylance (because this works in python)

Actual behaviour

data: Tuple[List[str], ...] = *map(example),

Pylance displays an error: Expected expression and selects the *-sign before the map statement

Logs

Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
[FG] parsing: /home/alve/dev/AoC-2020/8.py (1ms)
[FG] binding: /home/alve/dev/AoC-2020/8.py (0ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: analyze
[BG(1)] analyzing: /home/alve/dev/AoC-2020/8.py ...
[BG(1)]   parsing: /home/alve/dev/AoC-2020/8.py (4ms)
[BG(1)]   binding: /home/alve/dev/AoC-2020/8.py (0ms)
[BG(1)]   checking: /home/alve/dev/AoC-2020/8.py (9ms)
[BG(1)] analyzing: /home/alve/dev/AoC-2020/8.py (13ms)
Background analysis message: resumeAnalysis
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
[FG] parsing: /home/alve/dev/AoC-2020/8.py (6ms)
[FG] binding: /home/alve/dev/AoC-2020/8.py (1ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: analyze
[BG(1)] analyzing: /home/alve/dev/AoC-2020/8.py ...
[BG(1)]   parsing: /home/alve/dev/AoC-2020/8.py (5ms)
[BG(1)]   binding: /home/alve/dev/AoC-2020/8.py (1ms)
[BG(1)]   checking: /home/alve/dev/AoC-2020/8.py (39ms)
[BG(1)] analyzing: /home/alve/dev/AoC-2020/8.py (46ms)
Background analysis message: resumeAnalysis
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: markFilesDirty
Background analysis message: analyze
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
[FG] parsing: /home/alve/dev/AoC-2020/8.py (3ms)
[FG] binding: /home/alve/dev/AoC-2020/8.py (0ms)
Background analysis message: analyze
[BG(1)] analyzing: /home/alve/dev/AoC-2020/8.py ...
[BG(1)]   parsing: /home/alve/dev/AoC-2020/8.py (2ms)
[BG(1)]   binding: /home/alve/dev/AoC-2020/8.py (0ms)
[BG(1)]   checking: /home/alve/dev/AoC-2020/8.py (4ms)
[BG(1)] analyzing: /home/alve/dev/AoC-2020/8.py (6ms)
Background analysis message: resumeAnalysis
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: markFilesDirty
Background analysis message: analyze
[FG] parsing: /home/alve/.vscode/extensions/ms-python.vscode-pylance-2020.12.0/dist/typeshed-fallback/stdlib/2and3/_typeshed/__init__.pyi [fs read 0ms] (20ms)
[FG] binding: /home/alve/.vscode/extensions/ms-python.vscode-pylance-2020.12.0/dist/typeshed-fallback/stdlib/2and3/_typeshed/__init__.pyi (1ms)
[FG] parsing: /home/alve/.vscode/extensions/ms-python.vscode-pylance-2020.12.0/dist/typeshed-fallback/third_party/2and3/typing_extensions.pyi [fs read 0ms] (8ms)
[FG] binding: /home/alve/.vscode/extensions/ms-python.vscode-pylance-2020.12.0/dist/typeshed-fallback/third_party/2and3/typing_extensions.pyi (1ms)
[FG] parsing: /tmp/pyright-4278-BZYzwhKCkMnJ/builtins-4278-1Yvrj78E1t3t-.py [fs read 1ms] (126ms)
[FG] binding: /tmp/pyright-4278-BZYzwhKCkMnJ/builtins-4278-1Yvrj78E1t3t-.py (21ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange

Code Snippet / Additional information

from typing import List, Tuple, Any

example: Any = (["example code", "example code"])

data: Tuple[List[str], ...] = *map(str.split, example),
@github-actions github-actions bot added the triage label Dec 8, 2020
@erictraut
Copy link
Contributor

erictraut commented Dec 8, 2020

The code snippet that you've provided contains a syntax error because of a comma at the end. The Python interpreter reports an error ("SyntaxError: unexpected EOF while parsing").

If I delete the final comma, the Python interpreter reports "SyntaxError: can't use starred expression here". So I think Pylance is reporting the correct error here.

@alvesvaren
Copy link
Author

alvesvaren commented Dec 8, 2020

oh, I had the wrong snippet. I edited the issue, still the same problem, and no syntax error in python

@erictraut
Copy link
Contributor

Thanks for the bug report. I've confirmed that this is a bug in the parser. It's specific to the case where the LHS of an assignment is a variable with a type annotation and the RHS is a non-parenthesized tuple that starts with an unpack operator.

This will be fixed in the next release. I've added your sample as a unit test.

While you're waiting for the next release, you can work around the issue by enclosing the RHS (right hand side) of the assignment in parentheses.

@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 Dec 8, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.12.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#2020121-9-december-2020

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