[Python-3000] Ripping out exec

Georg Brandl g.brandl at gmx.net
Sat Sep 2 00:37:20 CEST 2006

Guido van Rossum wrote:
> On 9/1/06, Georg Brandl <g.brandl at gmx.net> wrote:
>> Guido van Rossum wrote:
>> > I would just rip it out.
>> It turns out that it's not so easy. The exec statement currently can
>> modify the locals, which means that
>> def f():
>>      exec "a=1"
>>      print a
>> succeeds. To make that possible, the compiler flags scopes containing
>> exec statements as unoptimized and does not assume unbound names to
>> be global.
>> With exec being a function, currently the above function won't work
>> because "a" is assumed to be global.
>> I can see only two resolutions:
>> * change exec() semantics so that it cannot modify the locals
>> * do not make exec a function
> Make it so it can't modify the locals. execfile() has the same limitation.

Good. Patch is at python.org/sf/1550800.

There's another one at python.org/sf/1550786 implementing the Ellipsis literal.


More information about the Python-3000 mailing list