Author congma
Recipients bruno.loff, congma
Date 2021-03-24.15:25:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1616599501.55.0.974031275466.issue43605@roundup.psfhosted.org>
In-reply-to
Content
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 ``NameError`` is raised.

In this case, inside the lambda's body the name "get" can't be resolved. For the lambda body, the name "get" is a nonlocal but there's no way to access a nonlocal in a lambda.

The comprehensions, like lambdas, are in their own nested scope.
History
Date User Action Args
2021-03-24 15:25:01congmasetrecipients: + congma, bruno.loff
2021-03-24 15:25:01congmasetmessageid: <1616599501.55.0.974031275466.issue43605@roundup.psfhosted.org>
2021-03-24 15:25:01congmalinkissue43605 messages
2021-03-24 15:25:01congmacreate