Skip to content

Commit faf1925

Browse files
committed
Remove usages of PyClassRef::from_pyobj
1 parent 00540de commit faf1925

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

vm/src/obj/objslice.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use num_bigint::BigInt;
22

33
use crate::function::PyFuncArgs;
4-
use crate::pyobject::{
5-
FromPyObjectRef, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TypeProtocol,
6-
};
4+
use crate::pyobject::{PyContext, PyObjectRef, PyResult, PyValue, TypeProtocol};
75
use crate::vm::VirtualMachine;
86

97
use super::objint;
@@ -57,14 +55,13 @@ fn slice_new(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
5755
Ok((cls, Some(start), Some(stop), step))
5856
}
5957
}?;
60-
Ok(PyObject::new(
61-
PySlice {
62-
start: start.map(|x| objint::get_value(x).clone()),
63-
stop: stop.map(|x| objint::get_value(x).clone()),
64-
step: step.map(|x| objint::get_value(x).clone()),
65-
},
66-
PyClassRef::from_pyobj(&cls),
67-
))
58+
PySlice {
59+
start: start.map(|x| objint::get_value(x).clone()),
60+
stop: stop.map(|x| objint::get_value(x).clone()),
61+
step: step.map(|x| objint::get_value(x).clone()),
62+
}
63+
.into_ref_with_type(vm, cls.clone().downcast().unwrap())
64+
.map(|x| x.into_object())
6865
}
6966

7067
fn get_property_value(vm: &VirtualMachine, value: &Option<BigInt>) -> PyResult {

vm/src/obj/objtype.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub fn type_new_class(
241241
bases.push(vm.ctx.object());
242242
let name = objstr::get_value(name);
243243
new(
244-
PyClassRef::from_pyobj(typ),
244+
typ.clone().downcast().unwrap(),
245245
&name,
246246
bases,
247247
objdict::py_dict_to_attributes(dict),
@@ -382,7 +382,7 @@ pub fn new(
382382
typ,
383383
}
384384
.into_ref();
385-
Ok(PyClassRef::from_pyobj(&new_type))
385+
Ok(new_type.downcast().unwrap())
386386
}
387387

388388
#[cfg(test)]

vm/src/pyobject.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ fn init_type_hierarchy() -> (PyClassRef, PyClassRef) {
206206
let object_type_ptr = PyObjectRef::into_raw(object_type.clone()) as *mut PyObject<PyClass>;
207207
let type_type_ptr = PyObjectRef::into_raw(type_type.clone()) as *mut PyObject<PyClass>;
208208

209-
let type_type = PyClassRef::from_pyobj(&type_type);
210-
let object_type = PyClassRef::from_pyobj(&object_type);
209+
let type_type: PyClassRef = type_type.downcast().unwrap();
210+
let object_type: PyClassRef = object_type.downcast().unwrap();
211211

212212
ptr::write(&mut (*object_type_ptr).typ, type_type.clone());
213213
ptr::write(&mut (*type_type_ptr).typ, type_type.clone());

0 commit comments

Comments
 (0)