forked from Rust-related/RustPython
Remove usages of PyClassRef::from_pyobj
This commit is contained in:
@@ -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<BigInt>) -> PyResult {
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -206,8 +206,8 @@ fn init_type_hierarchy() -> (PyClassRef, PyClassRef) {
|
||||
let object_type_ptr = PyObjectRef::into_raw(object_type.clone()) as *mut PyObject<PyClass>;
|
||||
let type_type_ptr = PyObjectRef::into_raw(type_type.clone()) as *mut PyObject<PyClass>;
|
||||
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user