diff --git a/vm/src/obj/objslice.rs b/vm/src/obj/objslice.rs index 9df435290..d68ae2255 100644 --- a/vm/src/obj/objslice.rs +++ b/vm/src/obj/objslice.rs @@ -1,9 +1,7 @@ use num_bigint::BigInt; use crate::function::PyFuncArgs; -use crate::pyobject::{ - FromPyObjectRef, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TypeProtocol, -}; +use crate::pyobject::{PyContext, PyObjectRef, PyResult, PyValue, TypeProtocol}; use crate::vm::VirtualMachine; use super::objint; @@ -57,14 +55,13 @@ fn slice_new(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { Ok((cls, Some(start), Some(stop), step)) } }?; - Ok(PyObject::new( - PySlice { - start: start.map(|x| objint::get_value(x).clone()), - stop: stop.map(|x| objint::get_value(x).clone()), - step: step.map(|x| objint::get_value(x).clone()), - }, - PyClassRef::from_pyobj(&cls), - )) + PySlice { + start: start.map(|x| objint::get_value(x).clone()), + stop: stop.map(|x| objint::get_value(x).clone()), + step: step.map(|x| objint::get_value(x).clone()), + } + .into_ref_with_type(vm, cls.clone().downcast().unwrap()) + .map(|x| x.into_object()) } fn get_property_value(vm: &VirtualMachine, value: &Option) -> PyResult { diff --git a/vm/src/obj/objtype.rs b/vm/src/obj/objtype.rs index 1b53226c9..b48ba9941 100644 --- a/vm/src/obj/objtype.rs +++ b/vm/src/obj/objtype.rs @@ -241,7 +241,7 @@ pub fn type_new_class( bases.push(vm.ctx.object()); let name = objstr::get_value(name); new( - PyClassRef::from_pyobj(typ), + typ.clone().downcast().unwrap(), &name, bases, objdict::py_dict_to_attributes(dict), @@ -382,7 +382,7 @@ pub fn new( typ, } .into_ref(); - Ok(PyClassRef::from_pyobj(&new_type)) + Ok(new_type.downcast().unwrap()) } #[cfg(test)] diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index deeb4f370..80eba36da 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -206,8 +206,8 @@ fn init_type_hierarchy() -> (PyClassRef, PyClassRef) { let object_type_ptr = PyObjectRef::into_raw(object_type.clone()) as *mut PyObject; let type_type_ptr = PyObjectRef::into_raw(type_type.clone()) as *mut PyObject; - let type_type = PyClassRef::from_pyobj(&type_type); - let object_type = PyClassRef::from_pyobj(&object_type); + let type_type: PyClassRef = type_type.downcast().unwrap(); + let object_type: PyClassRef = object_type.downcast().unwrap(); ptr::write(&mut (*object_type_ptr).typ, type_type.clone()); ptr::write(&mut (*type_type_ptr).typ, type_type.clone());