[ python-Bugs-1501934 ] incorrect LOAD/STORE_GLOBAL generation

SourceForge.net noreply at sourceforge.net
Mon Jun 19 19:44:30 CEST 2006


Bugs item #1501934, was opened at 2006-06-07 01:57
Message generated for change (Comment added) made by twouters
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1501934&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Parser/Compiler
Group: Python 2.5
Status: Open
Resolution: None
Priority: 8
Submitted By: Thomas Wouters (twouters)
Assigned to: Jeremy Hylton (jhylton)
Summary: incorrect LOAD/STORE_GLOBAL generation

Initial Comment:
Python 2.5 compiles the following piece of code
differently than Python 2.4:

g = 1
def f():
    g += 1

In Python 2.4, this raises an UnboundLocalError. In
current svn trunk, it will increment the global g by 1.
(dis.dis shows that it actually compiles into
LOAD/STORE_GLOBAL opcodes.) It seems the compiler
doesn't treat augmented assignment as assignment for
the purpose of determining locals, as this still fails
correctly:

g = 1
def f():
    g += 1
    g = 5

I can't find where this optimization happens nowadays,
but it feels like a short fix.


----------------------------------------------------------------------

>Comment By: Thomas Wouters (twouters)
Date: 2006-06-19 19:44

Message:
Logged In: YES 
user_id=34209

Possibly related is the discovery of free variables (used
when forming closures) and optimized-out codeblocks:

>>> def foo(x):
...     def bar():
...         if 0:
...             print x
...     return bar

In 2.4, there is no closure:
>>> foo.func_code.co_cellvars
()
>>> foo(5).func_closure
>>>

In 2.5, there is:
>>> foo.func_code.co_cellvars
('x',)
>>> foo(5).func_closure
(<cell at 0x2b9abf6d7e30: int object at 0x6b6580>,)

(I don't think it's unreasonable to declare the old
behaviour bugged, though :-)


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1501934&group_id=5470


More information about the Python-bugs-list mailing list