microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.67k stars 770 forks source link

Find All References on list comprehension var in notebook cell includes results from outer name scope #6026

Open debonte opened 1 week ago

debonte commented 1 week ago

Environment data

Code Snippet

# cell 0
j = "str"
[j for j in range(1, 6)]

# cell 1
j = 3

Repro Steps

  1. Create new notebook with two cells as shown above.
  2. Find All References on j within the list comprehension.

Expected behavior

Only the two references within the list comprehension are provided because the list comprehension is a separate name scope. This is the behavior you'll see if all three lines are in the same cell or are in a .py file.

image

Actual behavior

The use of the unrelated variable (also named j) in the second cell is also included:

image