Index: Python/ceval.c =================================================================== --- Python/ceval.c (revision 67679) +++ Python/ceval.c (working copy) @@ -1832,6 +1833,29 @@ PyTuple_GetItem(co->co_varnames, oparg) ); break; + case DELETE_DEREF: + x = freevars[oparg]; + if (PyCell_GET(x) != NULL) { + PyCell_Set(x, NULL); + continue; + } + /* Don't stomp existing exception */ + if (PyErr_Occurred()) + break; + if (oparg < PyTuple_GET_SIZE(co->co_cellvars)) { + v = PyTuple_GET_ITEM(co->co_cellvars, + oparg); + format_exc_check_arg( + PyExc_UnboundLocalError, + UNBOUNDLOCAL_ERROR_MSG, + v); + } else { + v = PyTuple_GET_ITEM(co->co_freevars, oparg - + PyTuple_GET_SIZE(co->co_cellvars)); + format_exc_check_arg(PyExc_NameError, + UNBOUNDFREE_ERROR_MSG, v); + } + break; case LOAD_CLOSURE: x = freevars[oparg]; Index: Python/compile.c =================================================================== --- Python/compile.c (revision 67679) +++ Python/compile.c (working copy) @@ -867,6 +867,8 @@ return 1; case STORE_DEREF: return -1; + case DELETE_DEREF: + return 0; default: fprintf(stderr, "opcode = %d\n", opcode); Py_FatalError("opcode_stack_effect()"); @@ -2542,13 +2544,7 @@ case AugLoad: case AugStore: break; - case Del: - PyErr_Format(PyExc_SyntaxError, - "can not delete variable '%S' referenced " - "in nested scope", - name); - Py_DECREF(mangled); - return 0; + case Del: op = DELETE_DEREF; break; case Param: default: PyErr_SetString(PyExc_SystemError, Index: Lib/opcode.py =================================================================== --- Lib/opcode.py (revision 67679) +++ Lib/opcode.py (working copy) @@ -162,6 +162,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)