Showing content from http://mail.python.org/pipermail/python-dev/attachments/20060607/d79597bd/attachment.html below:
<br>I just submitted <a href="http://python.org/sf/1501934">http://python.org/sf/1501934</a> and assigned it to Neal so it doesn't get forgotten before 2.5 goes out ;) It seems Python 2.5 compiles the following code incorrectly:
<br><br>>>> g = 1<br>>>> def f1():<br>... g += 1<br>... <br>>>> f1()<br>>>> g<br>2<br><br>It looks like the compiler is not seeing augmented assignment as creating a local name, as this fails properly:
<br><br clear="all">>>> def f2():<br>... g += 1<br>... g = 5<br>... <br>>>> f2()<br>Traceback (most recent call last):<br> File "<stdin>", line 1, in <module><br> File "<stdin>", line 2, in f2
<br>UnboundLocalError: local variable 'g' referenced before assignment<br><br>The dis.dis output confirms this:<br>>>> dis.dis(f1)<br> 1 0 LOAD_GLOBAL 0 (g)<br> 3 LOAD_CONST 1 (1)
<br> 6 INPLACE_ADD <br> 7 STORE_GLOBAL 0 (g)<br> 10 LOAD_CONST 0 (None)<br> 13 RETURN_VALUE <br><br>If anyone feels like fixing it and happens to remember where the new compiler does the fast-locals optimization (I recall a few people were working on extra optimizations and all), please do :-) (I can probably look at it before
2.5 if no one else does, though.) It may be a good idea to check for more such cornercases while we're at it (but I couldn't find any in the fast-locals bit.)<br><br>-- <br>Thomas Wouters <<a href="mailto:thomas@python.org">
thomas@python.org</a>><br><br>Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4