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 terry.reedy
Recipients chrisgmorton, terry.reedy
Date 2021-03-19.22:38:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1616193533.23.0.0813426742333.issue43481@roundup.psfhosted.org>
In-reply-to
Content
I cannot reproduce in Python with either 3.8 or 3.10.  (Please try with latter if you can.)  I thought the issue might possibly be passing two different dicts, which results in the code being executed as if in a class statement, but it is not.  

code = '''
c=[1,2,3,4]
d={'list': [c[i] for i in range(len(c))]}
print(d)
'''
bcode = compile(code, '', 'exec')
gdict = globals()
ldict = {}
exec(bcode, gdict, gdict)
exec(bcode, gdict, ldict)
class C:
    c=[1,2,3,4]
    d={'list': [c[i] for i in range(len(c))]}
    print(d)

prints {'list': [1, 2, 3, 4]} 3 times.  Using 'eval' instead of 'exec' gives the same.  I presume that code compiled with 'exec' is 'exec'ed even if use eval.
History
Date User Action Args
2021-03-19 22:38:53terry.reedysetrecipients: + terry.reedy, chrisgmorton
2021-03-19 22:38:53terry.reedysetmessageid: <1616193533.23.0.0813426742333.issue43481@roundup.psfhosted.org>
2021-03-19 22:38:53terry.reedylinkissue43481 messages
2021-03-19 22:38:53terry.reedycreate