mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
#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.
This commit is contained in:
parent
4785916d62
commit
ba117ef7e9
12 changed files with 113 additions and 45 deletions
|
@ -123,6 +123,7 @@ extern "C" {
|
|||
#define LOAD_CLOSURE 135 /* Load free variable from closure */
|
||||
#define LOAD_DEREF 136 /* Load and dereference from closure cell */
|
||||
#define STORE_DEREF 137 /* Store into cell */
|
||||
#define DELETE_DEREF 138 /* Delete closure cell */
|
||||
|
||||
/* The next 3 opcodes must be contiguous and satisfy
|
||||
(CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue