This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author veky
Recipients jpc, r.david.murray, veky
Date 2017-09-09.23:14:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1504998874.87.0.513220052881.issue31401@psf.upfronthosting.co.za>
In-reply-to
Content
List comprehension is irrelevant here, any nested function has the same problem. And the inner name doesn't have to refer to a function. Also, compilation as a separate step is not necessary.

So the minimal example is

    src = '''\
    a = 5
    def g(x): return a + x
    print(g(3))
    '''
    def comp(): exec(src)
    comp()

But I'm not sure if it is a bug at all. If you write explicitly

    exec(src, {})

you get a result 8 without problem. The docs say

    ...if the optional parts are omitted, the code is executed in the current scope.

And the current scope inside comp is "fast locals", where you can't really make new names. Maybe exec should raise an exception then, but it surely cannot just "work" inside fast locals scope.
History
Date User Action Args
2017-09-09 23:14:34vekysetrecipients: + veky, r.david.murray, jpc
2017-09-09 23:14:34vekysetmessageid: <1504998874.87.0.513220052881.issue31401@psf.upfronthosting.co.za>
2017-09-09 23:14:34vekylinkissue31401 messages
2017-09-09 23:14:34vekycreate