del statement support
Closed
KM
7mo ago+892+892+012345678901234567890123456789-43-43-01234567890123456789
del statement support
Implements del across the full pipeline — parsing, prepare, bytecode compilation, and VM
execution.
What works
del x— unbinds variables (locals, globals, cells), subsequent access raisesNameErroror
UnboundLocalErrorexactly as CPython doesdel d['key']— dict item removal via__delitem__del lst[i]— list item removal with negative index supportdel a, b— multi-target, executed left-to-right- Closures —
delon captured variables correctly propagates: outer scope gets
UnboundLocalError, inner closures getNameErrorfor free variables nonlocal+del— deleting vianonlocalunbinds the cell in the enclosing scope
New opcodes
DeleteSubscr— pops index + container, calls__delitem__DeleteLocalW— wide variant ofDeleteLocalfor slots > 255DeleteCell— storesUndefinedin a closure cell
All three appended to the enum to preserve discriminant stability.
Bug fix (pre-existing)
load_global was raising UnboundLocalError for undefined module-level variables that had
previously been assigned. CPython always raises NameError for globals. Fixed.
Not yet supported
del obj.attr— blocked on user-defined classes
Written in collaboration with claude-opus-4-6 and gpt-5.4-high