Pyright: Variable having the same name as the argument is reported as unbound in a lambda expression

Created on 21 Jul 2020  路  2Comments  路  Source: microsoft/pyright

Describe the bug
That var variable is referenced.

To Reproduce
N/A

Expected behavior
N/A

Screenshots or Code
image

def test():
    var = 0
    lambda var=var: ...

VS Code extension or command-line
coc-pyright with pyright 1.1.54

Additional context
FWIW, It is a common pattern of binding a variable to a argument to avoid lazy binding
https://github.com/satwikkansal/wtfpython#-the-sticky-output-function

>>> fns = [lambda x, i=i: x + i for i in range(10)]
>>> [fn(0) for fn in fns]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
addressed in next version bug

Most helpful comment

This is now implemented in Pyright 1.1.55, which I just published. It will also be included in the next release of Pylance.

All 2 comments

Thanks for the bug report. This will be fixed in the next version of Pyright and Pylance.

This is now implemented in Pyright 1.1.55, which I just published. It will also be included in the next release of Pylance.

Was this page helpful?
0 / 5 - 0 ratings