File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -29,3 +29,11 @@ def __del__(self):
2929def test_del_panic ():
3030 mytest = MyTest ()
3131 del mytest
32+
33+ # see https://github.com/RustPython/RustPython/issues/4910
34+
35+ def f ():
36+ del b # noqa
37+
38+ b = 'a'
39+ assert_raises (UnboundLocalError , f )
Original file line number Diff line number Diff line change @@ -607,7 +607,18 @@ impl ExecutingFrame<'_> {
607607 Ok ( None )
608608 }
609609 bytecode:: Instruction :: DeleteFast ( idx) => {
610- self . fastlocals . lock ( ) [ idx. get ( arg) as usize ] = None ;
610+ let mut fastlocals = self . fastlocals . lock ( ) ;
611+ let idx = idx. get ( arg) as usize ;
612+ if fastlocals[ idx] . is_none ( ) {
613+ return Err ( vm. new_exception_msg (
614+ vm. ctx . exceptions . unbound_local_error . to_owned ( ) ,
615+ format ! (
616+ "local variable '{}' referenced before assignment" ,
617+ self . code. varnames[ idx]
618+ ) ,
619+ ) ) ;
620+ }
621+ fastlocals[ idx] = None ;
611622 Ok ( None )
612623 }
613624 bytecode:: Instruction :: DeleteLocal ( idx) => {
You can’t perform that action at this time.
0 commit comments