diff --git a/vm/src/obj/objdict.rs b/vm/src/obj/objdict.rs index 70bdb0724e..267678b206 100644 --- a/vm/src/obj/objdict.rs +++ b/vm/src/obj/objdict.rs @@ -12,7 +12,6 @@ use super::objbool; use super::objiter; use super::objstr; use crate::dictdatatype; -use crate::obj::objtype; use crate::obj::objtype::PyClassRef; use crate::pyobject::PyClassImpl; @@ -215,24 +214,6 @@ impl PyDictRef { Err(vm.new_key_error(key.clone())) } - #[cfg_attr(feature = "flame-it", flame("PyDictRef"))] - pub fn get_item_option( - &self, - key: T, - vm: &VirtualMachine, - ) -> PyResult> { - match self.clone().inner_getitem(key.into_pyobject(vm)?, vm) { - Ok(value) => Ok(Some(value)), - Err(exc) => { - if objtype::isinstance(&exc, &vm.ctx.exceptions.key_error) { - Ok(None) - } else { - Err(exc) - } - } - } - } - fn get( self, key: PyObjectRef, diff --git a/vm/src/obj/objsuper.rs b/vm/src/obj/objsuper.rs index a9fb668cb8..016c2419c0 100644 --- a/vm/src/obj/objsuper.rs +++ b/vm/src/obj/objsuper.rs @@ -11,7 +11,7 @@ use crate::obj::objfunction::PyMethod; use crate::obj::objstr; use crate::obj::objtype::{PyClass, PyClassRef}; use crate::pyobject::{ - PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, + ItemProtocol, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, }; use crate::scope::NameProtocol; use crate::vm::VirtualMachine; diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 89e4611068..de17013e1a 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -1021,6 +1021,24 @@ pub trait ItemProtocol { vm: &VirtualMachine, ) -> PyResult; fn del_item(&self, key: T, vm: &VirtualMachine) -> PyResult; + + #[cfg_attr(feature = "flame-it", flame("PyDictRef"))] + fn get_item_option( + &self, + key: T, + vm: &VirtualMachine, + ) -> PyResult> { + match self.get_item(key, vm) { + Ok(value) => Ok(Some(value)), + Err(exc) => { + if objtype::isinstance(&exc, &vm.ctx.exceptions.key_error) { + Ok(None) + } else { + Err(exc) + } + } + } + } } impl ItemProtocol for PyObjectRef {