[Python-Dev] Re: let's not stretch a keyword's use unreasonably, _please_...

Alex Martelli aleaxit at yahoo.com
Sat Oct 25 04:58:05 EDT 2003

On Thursday 23 October 2003 07:51, Terry Reedy wrote:
> So I really *don't* need global.  Perhaps a new builtin
> def me():
>   import sys
>   return sys.modules[__name__]

Or, we can make the _compiler_ aware of what is going on (and get just the
same semantics as global) by accepting either a non-statement keyword 
(scope, as I suggested elsewhere) or a magicname for import, e.g.
import __me__ as Barry suggested.  Then __me__.x=23 can have just the
same semantics as today "x=23" has if there is some "global x" somewhere
around, and indeed it could be compiled into the same bytecode if __me__
was sufficiently special to the compiler.

[[ If __me__ was assigned to other objects, subjected to setattr, etc, it 
would lose all special powers, and become restricted to whatever 
restrictions may apply now or in the future to "setting stuff in other 
modules". ]]

We'd get more clarity _for human readers_ by thus flagging every 
assignment-to-module-level-name *in the very spot it's happening* and 
avoiding the inappropriate term "global" -- to the compiler it's all the
same, but humans are important, too.


More information about the Python-Dev mailing list