Pyright: Type inferring error about list comprehensions.

Created on 6 Nov 2019  路  3Comments  路  Source: microsoft/pyright

Describe the bug
Please see this example.
image

The variable a used in [a for a in range(10)] is a local variable, which should not influence the variable a outside the expression.

The code:

a = dict(m=1)
arr = [a for a in range(10)]
a["m"]

image

Additionally, if we change the list comprehension to generator expression, there will be the same problem.
Code:

a = dict(m=1)
arr = (a for a in range(10))
a["m"]

VS Code extension or command-line
VS Code extension version 1.0.83

addressed in next version bug

All 3 comments

Thanks for the bug report. I'm able to repro the problem as reported. I understand the underlying cause and will work on a solution.

This will be fixed in the next release of pyright.

This is now fixed in 1.0.84, which I just published.

Was this page helpful?
0 / 5 - 0 ratings