[Python-ideas] Allow imports to a global name

Nick Coghlan ncoghlan at gmail.com
Wed Apr 11 07:23:12 CEST 2012

On Wed, Apr 11, 2012 at 3:08 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> I found this slightly surprising, but on checking with dis, each of the
> 'implicit' assignments is implemented as the equivalent of x =
> internal_function_call(args).  (For for-loops, the assignment is within the
> loop.) Which is to say, each bytecode sequence ends with store_xxx where xxx
> is 'fast' or 'global. So now I am not surprised.

By contrast, I already knew that CPython's underlying implementation
of the name binding step was the same in all these cases, so I was
surprised by the documented restriction in the language spec.

I'm now wondering if the initial restriction that prompted the note in
the language spec was something that existed in the pre-AST version of
the compiler (I only started learning the code generation machinery
when I was helping to get the AST based compiler branch ready for
inclusion in Python 2.5, so I know very little about how the compiler
used to work in 2.4 and earlier)


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list