diff options
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/dis.rst | 6 | ||||
-rw-r--r-- | Doc/reference/simple_stmts.rst | 9 | ||||
-rw-r--r-- | Doc/whatsnew/3.2.rst | 25 |
3 files changed, 35 insertions, 5 deletions
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index fb62ec1..8e57dd4 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -723,6 +723,12 @@ the more significant byte last. storage. +.. opcode:: DELETE_DEREF (i) + + Empties the cell contained in slot *i* of the cell and free variable storage. + Used by the :keyword:`del` statement. + + .. opcode:: SET_LINENO (lineno) This opcode is obsolete. diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst index 378efc7..4082aa7 100644 --- a/Doc/reference/simple_stmts.rst +++ b/Doc/reference/simple_stmts.rst @@ -388,11 +388,6 @@ namespace, depending on whether the name occurs in a :keyword:`global` statement in the same code block. If the name is unbound, a :exc:`NameError` exception will be raised. -.. index:: pair: free; variable - -It is illegal to delete a name from the local namespace if it occurs as a free -variable in a nested block. - .. index:: pair: attribute; deletion Deletion of attribute references, subscriptions and slicings is passed to the @@ -400,6 +395,10 @@ primary object involved; deletion of a slicing is in general equivalent to assignment of an empty slice of the right type (but even this is determined by the sliced object). +.. versionchanged:: 3.2 + Previously it was illegal to delete a name from the local namespace if it + occurs as a free variable in a nested block. + .. _return: 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 ===================================== |