Cong Ma added the comment:
I think this is in the same class of behaviours as
```
def func(l):
def get(i):
return l[i]
print(eval("(lambda x: get(x))(0)")) # Call anonymous lambda with the
constant 0 as argument
```
Calls like ``func(["spam"])`` will not "work", and ``NameE
New submission from Bruno Loff :
Python 3.9.2 seems to be giving me some unexpected difficulty evaluating
generators inside evals. Here is the example:
```python
def func(l):
def get(i):
return l[i]
print(sum(get(i) for i in range(len(l # works as expected, prints 10