Roundup Tracker - Issues

Message6458

Author tekberg
Recipients joseph_myers, rouilj, tekberg
Date 2019-04-08.20:12:31
Message-id <1554754351.5.0.456185763508.issue2551026@roundup.psfhosted.org>
In-reply-to
Sent a query to python-porting@python.org and got back a reasonable
response from Piet van Oostrum  explaining the situation. Here is the
body of his response:

Tom Ekberg wrote:
 >
 > My question to this group:
 >
 > Do you have knowledge of the different contents of __code__.co_names
between Python 2.7 and Python
 > 3.5? I'm expecting that this is a difference that is documented
somewhere.
 >

The difference is that in Python 3 a (list) comprehension is compiled
into an anonymous function, to prevent the leaking of the control
variable (x in this case). The base from which the list is constructed
(i.e. the expression after 'in') is given as the argument to this
function, so any variable in that part appears in co_names. But the rest
of the comprehension is part of that anonymous function, so in this case
the names 'realname' and 'user_realnames' are not local to your function
'f', but of the anonymous function.

In Python 2, the list comprehension was compiled inline.
History
Date User Action Args
2019-04-08 20:12:31tekbergsetmessageid: <1554754351.5.0.456185763508.issue2551026@roundup.psfhosted.org>
2019-04-08 20:12:31tekbergsetrecipients: + tekberg, rouilj, joseph_myers
2019-04-08 20:12:31tekberglinkissue2551026 messages
2019-04-08 20:12:31tekbergcreate