Roundup Tracker - Issues


Author tekberg
Recipients joseph_myers, rouilj, tekberg
Date 2019-04-08.20:12:31
Message-id <>
Sent a query to 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

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.
Date User Action Args
2019-04-08 20:12:31tekbergsetmessageid: <>
2019-04-08 20:12:31tekbergsetrecipients: + tekberg, rouilj, joseph_myers
2019-04-08 20:12:31tekberglinkissue2551026 messages
2019-04-08 20:12:31tekbergcreate