The scoping around comprehensions is a bit confusing and our logic doesn't capture it correctly. Consider this case which we currently sort incorrectly:
def f():
g()
return [g for g in range(10)]
def g():
print("Called g")
In the above snippet, the g() invocation within f and the g reference within the list comprehension exist within two separate scopes. Therefore, the invocation of g() should NOT be considered a call to a variable within the local scope. That is, function f does indeed have a requirement on the global function g.
This PR fixes this scoping issue and introduces additional tests to assert correctness of these cases.
The scoping around comprehensions is a bit confusing and our logic doesn't capture it correctly. Consider this case which we currently sort incorrectly:
In the above snippet, the
g()
invocation withinf
and theg
reference within the list comprehension exist within two separate scopes. Therefore, the invocation ofg()
should NOT be considered a call to a variable within the local scope. That is, functionf
does indeed have a requirement on the global functiong
.This PR fixes this scoping issue and introduces additional tests to assert correctness of these cases.