diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 39cea1467..cfe2ff2d0 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -538,11 +538,14 @@ impl ExecutingFrame<'_> { } bytecode::Instruction::LoadNameAny(idx) => { let name = self.code.names[*idx as usize]; - let value = self.locals.mapping().subscript(name, vm).ok(); - self.push_value(match value { - Some(x) => x, - None => self.load_global_or_builtin(name, vm)?, - }); + let result = self.locals.mapping().subscript(name, vm); + match result { + Ok(x) => self.push_value(x), + Err(e) if e.class().is(vm.ctx.exceptions.key_error) => { + self.push_value(self.load_global_or_builtin(name, vm)?); + } + Err(e) => return Err(e), + } Ok(None) } bytecode::Instruction::LoadGlobal(idx) => {