diff --git a/vm/src/builtins/genericalias.rs b/vm/src/builtins/genericalias.rs index fc67117cb..d8a47db73 100644 --- a/vm/src/builtins/genericalias.rs +++ b/vm/src/builtins/genericalias.rs @@ -102,7 +102,7 @@ impl PyGenericAlias { Ok(format!( "{}[{}]", - repr_item(self.origin.as_object().to_owned(), vm)?, + repr_item(self.origin.clone().into(), vm)?, if self.args.len() == 0 { "()".to_owned() } else { @@ -118,17 +118,17 @@ impl PyGenericAlias { #[pyproperty(magic)] fn parameters(&self) -> PyObjectRef { - self.parameters.as_object().to_owned() + self.parameters.clone().into() } #[pyproperty(magic)] fn args(&self) -> PyObjectRef { - self.args.as_object().to_owned() + self.args.clone().into() } #[pyproperty(magic)] fn origin(&self) -> PyObjectRef { - self.origin.as_object().to_owned() + self.origin.clone().into() } #[pymethod(magic)] diff --git a/vm/src/builtins/module.rs b/vm/src/builtins/module.rs index 1d34d0e63..4ff2d7de9 100644 --- a/vm/src/builtins/module.rs +++ b/vm/src/builtins/module.rs @@ -52,7 +52,7 @@ impl PyModule { fn getattr_inner(zelf: &PyObjectView, name: PyStrRef, vm: &VirtualMachine) -> PyResult { if let Some(attr) = - vm.generic_getattribute_opt(zelf.as_object().to_owned(), name.clone(), None)? + vm.generic_getattribute_opt(zelf.to_owned().into(), name.clone(), None)? { return Ok(attr); } diff --git a/vm/src/dictdatatype.rs b/vm/src/dictdatatype.rs index 0f47f801c..398912c68 100644 --- a/vm/src/dictdatatype.rs +++ b/vm/src/dictdatatype.rs @@ -10,7 +10,7 @@ use crate::common::{ use crate::{ builtins::{PyInt, PyStr, PyStrRef}, function::IntoPyObject, - AsPyObject, PyObject, PyObjectRef, PyObjectWrap, PyRefExact, PyResult, VirtualMachine, + AsPyObject, PyObject, PyObjectRef, PyRefExact, PyResult, VirtualMachine, }; use num_traits::ToPrimitive; use std::{fmt, mem::size_of, ops::ControlFlow}; @@ -846,7 +846,7 @@ impl DictKey for usize { } } else { let int = vm.ctx.new_int(*self); - vm.bool_eq(&int.into_object(), other_key) + vm.bool_eq(int.as_ref(), other_key) } } diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 1c52b942f..335196b1d 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -79,7 +79,7 @@ impl VirtualMachine { // This function should not be called directly, // use `wite_exception` as a public interface. // It is similar to `print_exception_recursive` from `CPython`. - seen.insert(exc.as_object().get_id()); + seen.insert(exc.get_id()); #[allow(clippy::manual_map)] if let Some((cause_or_context, msg)) = if let Some(cause) = exc.cause() { @@ -102,11 +102,11 @@ impl VirtualMachine { } else { None } { - if !seen.contains(&cause_or_context.as_object().get_id()) { + if !seen.contains(&cause_or_context.get_id()) { self.write_exception_recursive(output, &cause_or_context, seen)?; writeln!(output, "{}", msg)?; } else { - seen.insert(cause_or_context.as_object().get_id()); + seen.insert(cause_or_context.get_id()); } } @@ -494,9 +494,9 @@ impl PyBaseException { } #[pymethod] - fn with_traceback(zelf: PyRef, tb: Option) -> PyResult { + fn with_traceback(zelf: PyRef, tb: Option) -> PyResult> { *zelf.traceback.write() = tb; - Ok(zelf.as_object().to_owned()) + Ok(zelf) } #[pymethod(magic)] diff --git a/vm/src/vm_ops.rs b/vm/src/vm_ops.rs index 3fd977383..ade8a14a4 100644 --- a/vm/src/vm_ops.rs +++ b/vm/src/vm_ops.rs @@ -33,6 +33,7 @@ impl VirtualMachine { }) } + #[inline] pub fn bool_eq(&self, a: &PyObject, b: &PyObject) -> PyResult { a.rich_compare_bool(b, PyComparisonOp::Eq, self) }