Mercurial > cpython-lru_cache-weakref
diff Lib/opcode.py @ 64620:25cc226dc9bd
#4617: Previously it was illegal to delete a name from the local
namespace if it occurs as a free variable in a nested block. This limitation
of the compiler has been lifted, and a new opcode introduced (DELETE_DEREF).
This sample was valid in 2.6, but fails to compile in 3.x without this change::
>>> def f():
... def print_error():
... print(e)
... try:
... something
... except Exception as e:
... print_error()
... # implicit "del e" here
This sample has always been invalid in Python, and now works::
>>> def outer(x):
... def inner():
... return x
... inner()
... del x
There is no need to bump the PYC magic number: the new opcode is used
for code that did not compile before.
| author | Amaury Forgeot d'Arc <amauryfa@gmail.com> |
|---|---|
| date | Fri, 10 Sep 2010 21:39:53 +0000 |
| parents | 725231211273 |
| children | d30b54ffd5e8 |
line wrap: on
line diff
--- a/Lib/opcode.py Fri Sep 10 20:43:53 2010 +0000 +++ b/Lib/opcode.py Fri Sep 10 21:39:53 2010 +0000 @@ -161,6 +161,8 @@ hasfree.append(136) def_op('STORE_DEREF', 137) hasfree.append(137) +def_op('DELETE_DEREF', 138) +hasfree.append(138) def_op('CALL_FUNCTION_VAR', 140) # #args + (#kwargs << 8) def_op('CALL_FUNCTION_KW', 141) # #args + (#kwargs << 8)
