Author ggenellina
Recipients benjamin.peterson, ezio.melotti, ggenellina
Date 2009-11-16.09:38:26
SpamBayes Score 6.01185e-07
Marked as misclassified No
Message-id <>
The compiler doesn't know how the code is going to be used apart from 
the "mode" parameter:

py> c=compile("x=1","","exec")
py> import dis
py> dis.dis(c)
  1           0 LOAD_CONST               0 (1)
              3 STORE_NAME               0 (x)
              6 LOAD_CONST               1 (None)
              9 RETURN_VALUE
py> c=compile("global x; x=1","","exec")
py> dis.dis(c)
  1           0 LOAD_CONST               0 (1)
              3 STORE_GLOBAL             0 (x)
              6 LOAD_CONST               1 (None)
              9 RETURN_VALUE

The generated code is different, and I may exec it at global or local 
scope, with different results. 

compile would require a new mode, different from "exec", to 
mean "compile this as a module at global scope; forbid global 

If not, this would become invalid:

def foo():
  c=compile("global x; x=1","","exec")
  exec c

since -at the compile phase- the code is indistinghishable from a 

Also, since PEP3003 has been approved (moratorium), language changes 
like this will have to wait a few years.
Date User Action Args
2009-11-16 09:38:28ggenellinasetrecipients: + ggenellina, benjamin.peterson, ezio.melotti
2009-11-16 09:38:28ggenellinasetmessageid: <>
2009-11-16 09:38:26ggenellinalinkissue7329 messages
2009-11-16 09:38:26ggenellinacreate