[Python-Dev] effect of "exec" on local scope

Nick Coghlan ncoghlan at gmail.com
Thu Oct 9 13:27:47 CEST 2008


Guido van Rossum wrote:
> Well, I don't recall what CLPython is, but I believe it is broken and
> that code should work -- there are (or used to be) examples of using
> exec to populate classes in the standard library so while it may look
> dodgy it really is exected to work...

I think this behaviour (modifying locals() at class scope) was actually
implicitly blessed in PEP 3115, even though that PEP doesn't explicitly
state locals() in a class body is required to grant access to the
namespace returned by __prepare__().

Perhaps the time is right for the locals() documentation to be more
explicit regarding when modifying its contents will affect the current
namespace?
- yes at module scope (effectively the same as globals())
- yes at class scope
- maybe (but typically not) at function scope

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
            http://www.boredomandlaziness.org


More information about the Python-Dev mailing list