diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2010-09-10 21:39:53 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2010-09-10 21:39:53 (GMT) |
commit | ba117ef7e9b2f7f2fbec62a9fcfe371a68024769 (patch) | |
tree | 3ca491174a99860c368d8d243d8db31b13b6ecf8 /Doc/whatsnew/3.2.rst | |
parent | 4785916d62aeb97692bab08bb9e77952853084a4 (diff) | |
download | cpython-ba117ef7e9b2f7f2fbec62a9fcfe371a68024769.zip cpython-ba117ef7e9b2f7f2fbec62a9fcfe371a68024769.tar.gz cpython-ba117ef7e9b2f7f2fbec62a9fcfe371a68024769.tar.bz2 |
#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.
Diffstat (limited to 'Doc/whatsnew/3.2.rst')
-rw-r--r-- | Doc/whatsnew/3.2.rst | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst index 7d8970b..bd38a7e 100644 --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -240,6 +240,31 @@ Some smaller changes made to the core Python language are: (See :issue:`8188`.) +* Previously it was illegal to delete a name from the local namespace if it + occurs as a free variable in a nested block:: + + >>> def outer(x): + ... def inner(): + ... return x + ... inner() + ... del x + + This is now allowed. Remember that the target of an :keyword:`except` clause + is cleared, so this code which used to work with Python 2.6, raised a + :exc:`SyntaxError` with Python 3.1 and now works again:: + + >>> def f(): + ... def print_error(): + ... print(e) + ... try: + ... something + ... except Exception as e: + ... print_error() + ... # implicit "del e" here + + (See :issue:`4617`.) + + New, Improved, and Deprecated Modules ===================================== |