]> granicus.if.org Git - python/commit
#4617: Previously it was illegal to delete a name from the local
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Fri, 10 Sep 2010 21:39:53 +0000 (21:39 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Fri, 10 Sep 2010 21:39:53 +0000 (21:39 +0000)
commitba117ef7e9b2f7f2fbec62a9fcfe371a68024769
tree3ca491174a99860c368d8d243d8db31b13b6ecf8
parent4785916d62aeb97692bab08bb9e77952853084a4
#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.
12 files changed:
Doc/library/dis.rst
Doc/reference/simple_stmts.rst
Doc/whatsnew/3.2.rst
Include/opcode.h
Lib/opcode.py
Lib/test/test_exceptions.py
Lib/test/test_scope.py
Lib/test/test_syntax.py
Misc/NEWS
Python/ceval.c
Python/compile.c
Python/opcode_targets.h