diff --git a/vm/src/builtins/dict.rs b/vm/src/builtins/dict.rs index 599f94486..23348fd66 100644 --- a/vm/src/builtins/dict.rs +++ b/vm/src/builtins/dict.rs @@ -18,7 +18,7 @@ use crate::{ protocol::{PyIterIter, PyIterReturn, PyMappingMethods, PySequenceMethods}, recursion::ReprGuard, types::{ - AsMapping, AsSequence, Callable, Comparable, Constructor, Hashable, IterNext, + AsMapping, AsSequence, Callable, Comparable, Constructor, Hashable, Initializer, IterNext, IterNextIterable, Iterable, PyComparisonOp, Unconstructible, Unhashable, }, vm::VirtualMachine, @@ -67,7 +67,7 @@ impl PyDict { // Python dict methods: #[allow(clippy::len_without_is_empty)] #[pyimpl( - with(AsMapping, Hashable, Comparable, Iterable, AsSequence), + with(Initializer, AsMapping, Hashable, Comparable, Iterable, AsSequence), flags(BASETYPE) )] impl PyDict { @@ -88,14 +88,6 @@ impl PyDict { .map(Into::into) } - #[pyslot] - #[pymethod(magic)] - fn init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> { - let zelf: PyRef = zelf.try_into_value(vm)?; - let (dict_obj, kwargs): (OptionalArg, KwArgs) = args.bind(vm)?; - zelf.update(dict_obj, kwargs, vm) - } - // Used in update and ior. fn merge_object( dict: &DictContentType, @@ -462,6 +454,18 @@ impl PyDict { }; } +impl Initializer for PyDict { + type Args = (OptionalArg, KwArgs); + + fn init( + zelf: PyRef, + (dict_obj, kwargs): Self::Args, + vm: &VirtualMachine, + ) -> PyResult<()> { + zelf.update(dict_obj, kwargs, vm) + } +} + impl AsMapping for PyDict { fn as_mapping(_zelf: &Py, _vm: &VirtualMachine) -> PyMappingMethods { Self::MAPPING_METHODS