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

Unpacking multiple iterables yields false negatives #2371

Closed
derhintze opened this issue Feb 11, 2022 · 7 comments
Closed

Unpacking multiple iterables yields false negatives #2371

derhintze opened this issue Feb 11, 2022 · 7 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

@derhintze
Copy link

Environment data

  • Language Server version: 2022.2.1 (pyright 618f54ed)
  • OS and version: Red Hat 4.8.5-44
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.9.1

Expected behaviour

To not flag anything as wrong.

Actual behaviour

Multiple errors errors found:

  • Expected expression
  • Expected ":"
  • Only one unpack operation allowed in list

Logs

(25626) Background analysis message: setFileOpened
(25626) Background analysis message: getDiagnosticsForRange
(25626) Background analysis message: getDiagnosticsForRange
(25626) Background analysis message: getSemanticTokens full
(25626) [BG(1)] getSemanticTokens full at /radarugs/hintze/s4-cnc-tools/test.py (5ms)
(25626) Background analysis message: analyze

Code Snippet / Additional information

The following executes w/o problems in Python:

a = [1, 2]
b = ["3", "4"]

for x in *a, *b:
    print(x)

c = *a, *b
print(c)

Yields the following output:

1
2
3
4
(1, 2, '3', '4')

But pylance marks the first * in line 4 (the for-loop) with Expected expression, the colon in the same line as Expected ":", and the second unpacking in line 7 (where c is assigned) as Only one unpack operation allowed in list.

This is probably (partly?) related to #700.

@derhintze
Copy link
Author

Black also doesn't understand this expression: psf/black#2878

@derhintze
Copy link
Author

also note that this syntax is only valid for Python >= 3.9

@erictraut
Copy link
Contributor

Thanks for the bug report. I wasn't aware of this change to the grammar in Python 3.9. Since this is a core type checker issue, I've created a tracking bug in the pyright repo. microsoft/pyright#3029

@erictraut
Copy link
Contributor

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 Feb 11, 2022
@debonte
Copy link
Contributor

debonte commented Feb 17, 2022

This issue has been fixed in version 2022.2.3, which we've just released. You can find the changelog here: CHANGELOG.md

@debonte debonte closed this as completed Feb 17, 2022
@realworldhacker
Copy link

realworldhacker commented Sep 15, 2023

expected expression error in visual studio code from an elif statement I tried to run. parenthesis only fixed if statement error, I', finding a hard time finding a solution for my current problem. following a PyCharm tutorial btw; but I'm having a hard time downloading it. https://www.youtube.com/watch?v=0fC1JsN8AsM 39:42

@debonte
Copy link
Contributor

debonte commented Sep 19, 2023

@realworldhacker, I copied the code from that spot in the video (see below) and Pylance doesn't show any errors for me, so I'm assuming you have a typo somewhere in the code. One wild guess is that you typed elif instead of else on the second to last line.

If you believe that there is a problem with Pylance here, please open a new issue and include a minimal code snippet that reproduces the problem.

fnum = input("What is the first number ")
snum = input("What is the second number")

if fnum > snum:
    print("The first number is larger!")
elif snum > fnum:
    print("The second number is larger. ")
else:
    print("The numbers are the same")

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

4 participants