diff --git a/crates/stdlib/src/csv.rs b/crates/stdlib/src/csv.rs index 792402e058..a62594a9f1 100644 --- a/crates/stdlib/src/csv.rs +++ b/crates/stdlib/src/csv.rs @@ -4,7 +4,8 @@ pub(crate) use _csv::make_module; mod _csv { use crate::common::lock::PyMutex; use crate::vm::{ - AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, + AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, + VirtualMachine, builtins::{PyBaseExceptionRef, PyInt, PyNone, PyStr, PyType, PyTypeRef}, function::{ArgIterable, ArgumentError, FromArgs, FuncArgs, OptionalArg}, protocol::{PyIter, PyIterReturn}, @@ -130,11 +131,11 @@ mod _csv { /// /// * If the 'delimiter' attribute is not a single-character string, a type error is returned. /// * If the 'obj' is not of string type and does not have a 'delimiter' attribute, a type error is returned. - fn parse_delimiter_from_obj(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult { + fn parse_delimiter_from_obj(vm: &VirtualMachine, obj: &PyObject) -> PyResult { if let Ok(attr) = obj.get_attr("delimiter", vm) { parse_delimiter_from_obj(vm, &attr) } else { - match_class!(match obj.clone() { + match_class!(match obj.to_owned() { s @ PyStr => { Ok(s.as_str().bytes().exactly_one().map_err(|_| { let msg = r#""delimiter" must be a 1-character string"#; @@ -148,7 +149,7 @@ mod _csv { }) } } - fn parse_quotechar_from_obj(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult> { + fn parse_quotechar_from_obj(vm: &VirtualMachine, obj: &PyObject) -> PyResult> { match_class!(match obj.get_attr("quotechar", vm)? { s @ PyStr => { Ok(Some(s.as_str().bytes().exactly_one().map_err(|_| { @@ -169,7 +170,7 @@ mod _csv { } }) } - fn parse_escapechar_from_obj(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult> { + fn parse_escapechar_from_obj(vm: &VirtualMachine, obj: &PyObject) -> PyResult> { match_class!(match obj.get_attr("escapechar", vm)? { s @ PyStr => { Ok(Some(s.as_str().bytes().exactly_one().map_err(|_| { @@ -191,10 +192,7 @@ mod _csv { } }) } - fn prase_lineterminator_from_obj( - vm: &VirtualMachine, - obj: &PyObjectRef, - ) -> PyResult { + fn prase_lineterminator_from_obj(vm: &VirtualMachine, obj: &PyObject) -> PyResult { match_class!(match obj.get_attr("lineterminator", vm)? { s @ PyStr => { Ok(if s.as_bytes().eq(b"\r\n") { @@ -217,7 +215,7 @@ mod _csv { } }) } - fn prase_quoting_from_obj(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult { + fn prase_quoting_from_obj(vm: &VirtualMachine, obj: &PyObject) -> PyResult { match_class!(match obj.get_attr("quoting", vm)? { i @ PyInt => { Ok(i.try_to_primitive::(vm)?.try_into().map_err(|_| { diff --git a/crates/stdlib/src/openssl.rs b/crates/stdlib/src/openssl.rs index ea67d605f7..bf03813b18 100644 --- a/crates/stdlib/src/openssl.rs +++ b/crates/stdlib/src/openssl.rs @@ -56,7 +56,8 @@ mod _ssl { vm::{ AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::{ - PyBaseExceptionRef, PyBytesRef, PyListRef, PyOSError, PyStrRef, PyTypeRef, PyWeak, + PyBaseException, PyBaseExceptionRef, PyBytesRef, PyListRef, PyOSError, PyStrRef, + PyTypeRef, PyWeak, }, class_or_notimplemented, convert::ToPyException, @@ -3351,7 +3352,7 @@ mod _ssl { // Helper function to set verify_code and verify_message on SSLCertVerificationError fn set_verify_error_info( - exc: &PyBaseExceptionRef, + exc: &Py, ssl_ptr: *const sys::SSL, vm: &VirtualMachine, ) { diff --git a/crates/stdlib/src/scproxy.rs b/crates/stdlib/src/scproxy.rs index f49b6890a6..1974e7814a 100644 --- a/crates/stdlib/src/scproxy.rs +++ b/crates/stdlib/src/scproxy.rs @@ -5,8 +5,8 @@ mod _scproxy { // straight-forward port of Modules/_scproxy.c use crate::vm::{ - PyResult, VirtualMachine, - builtins::{PyDictRef, PyStr}, + Py, PyResult, VirtualMachine, + builtins::{PyDict, PyDictRef, PyStr}, convert::ToPyObject, }; use system_configuration::core_foundation::{ @@ -74,7 +74,7 @@ mod _scproxy { let result = vm.ctx.new_dict(); - let set_proxy = |result: &PyDictRef, + let set_proxy = |result: &Py, proto: &str, enabled_key: CFStringRef, host_key: CFStringRef, diff --git a/crates/stdlib/src/ssl.rs b/crates/stdlib/src/ssl.rs index c23062d639..e6f8c5fda7 100644 --- a/crates/stdlib/src/ssl.rs +++ b/crates/stdlib/src/ssl.rs @@ -1423,7 +1423,7 @@ mod _ssl { /// Helper: Get path from Python's os.environ fn get_env_path( - environ: &PyObjectRef, + environ: &PyObject, var_name: &str, vm: &VirtualMachine, ) -> PyResult { @@ -2101,10 +2101,10 @@ mod _ssl { // Helper functions (private): /// Parse path argument (str or bytes) to string - fn parse_path_arg(arg: &PyObjectRef, vm: &VirtualMachine) -> PyResult { - if let Ok(s) = PyStrRef::try_from_object(vm, arg.clone()) { + fn parse_path_arg(arg: &PyObject, vm: &VirtualMachine) -> PyResult { + if let Ok(s) = PyStrRef::try_from_object(vm, arg.to_owned()) { Ok(s.as_str().to_owned()) - } else if let Ok(b) = ArgBytesLike::try_from_object(vm, arg.clone()) { + } else if let Ok(b) = ArgBytesLike::try_from_object(vm, arg.to_owned()) { String::from_utf8(b.borrow_buf().to_vec()) .map_err(|_| vm.new_value_error("path contains invalid UTF-8".to_owned())) } else { @@ -2279,10 +2279,10 @@ mod _ssl { } /// Helper: Parse cadata argument (str or bytes) - fn parse_cadata_arg(&self, arg: &PyObjectRef, vm: &VirtualMachine) -> PyResult> { - if let Ok(s) = PyStrRef::try_from_object(vm, arg.clone()) { + fn parse_cadata_arg(&self, arg: &PyObject, vm: &VirtualMachine) -> PyResult> { + if let Ok(s) = PyStrRef::try_from_object(vm, arg.to_owned()) { Ok(s.as_str().as_bytes().to_vec()) - } else if let Ok(b) = ArgBytesLike::try_from_object(vm, arg.clone()) { + } else if let Ok(b) = ArgBytesLike::try_from_object(vm, arg.to_owned()) { Ok(b.borrow_buf().to_vec()) } else { Err(vm.new_type_error("cadata should be a str or bytes".to_owned())) diff --git a/crates/stdlib/src/ssl/compat.rs b/crates/stdlib/src/ssl/compat.rs index 798542f210..4ccc590360 100644 --- a/crates/stdlib/src/ssl/compat.rs +++ b/crates/stdlib/src/ssl/compat.rs @@ -23,10 +23,10 @@ use rustls::server::ResolvesServerCert; use rustls::server::ServerConfig; use rustls::server::ServerConnection; use rustls::sign::CertifiedKey; -use rustpython_vm::builtins::PyBaseExceptionRef; +use rustpython_vm::builtins::{PyBaseException, PyBaseExceptionRef}; use rustpython_vm::convert::IntoPyException; use rustpython_vm::function::ArgBytesLike; -use rustpython_vm::{AsObject, PyObjectRef, PyPayload, PyResult, TryFromObject}; +use rustpython_vm::{AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject}; use std::io::Read; use std::sync::{Arc, Once}; @@ -984,7 +984,7 @@ pub(super) fn create_client_config(options: ClientConfigOptions) -> Result bool { +pub(super) fn is_blocking_io_error(err: &Py, vm: &VirtualMachine) -> bool { err.fast_isinstance(vm.ctx.exceptions.blocking_io_error) } @@ -1534,7 +1534,7 @@ fn ssl_read_tls_records( /// Check if an exception is a connection closed error /// In SSL context, these errors indicate unexpected connection termination without proper TLS shutdown -fn is_connection_closed_error(exc: &PyBaseExceptionRef, vm: &VirtualMachine) -> bool { +fn is_connection_closed_error(exc: &Py, vm: &VirtualMachine) -> bool { use rustpython_vm::stdlib::errno::errors; // Check for ConnectionAbortedError, ConnectionResetError (Python exception types) diff --git a/crates/vm/src/builtins/builtin_func.rs b/crates/vm/src/builtins/builtin_func.rs index d25188affd..da5fd5e807 100644 --- a/crates/vm/src/builtins/builtin_func.rs +++ b/crates/vm/src/builtins/builtin_func.rs @@ -51,11 +51,11 @@ impl PyNativeFunction { } // PyCFunction_GET_SELF - pub const fn get_self(&self) -> Option<&PyObjectRef> { + pub fn get_self(&self) -> Option<&PyObject> { if self.value.flags.contains(PyMethodFlags::STATIC) { return None; } - self.zelf.as_ref() + self.zelf.as_deref() } pub const fn as_func(&self) -> &'static dyn PyNativeFn { diff --git a/crates/vm/src/builtins/dict.rs b/crates/vm/src/builtins/dict.rs index b34299d417..04915b035f 100644 --- a/crates/vm/src/builtins/dict.rs +++ b/crates/vm/src/builtins/dict.rs @@ -753,7 +753,7 @@ impl ExactSizeIterator for DictIter<'_> { trait DictView: PyPayload + PyClassDef + Iterable + Representable { type ReverseIter: PyPayload + std::fmt::Debug; - fn dict(&self) -> &PyDictRef; + fn dict(&self) -> &Py; fn item(vm: &VirtualMachine, key: PyObjectRef, value: PyObjectRef) -> PyObjectRef; #[pymethod] @@ -785,7 +785,7 @@ macro_rules! dict_view { impl DictView for $name { type ReverseIter = $reverse_iter_name; - fn dict(&self) -> &PyDictRef { + fn dict(&self) -> &Py { &self.dict } @@ -1142,7 +1142,7 @@ impl PyDictKeys { #[pygetset] fn mapping(zelf: PyRef) -> PyMappingProxy { - PyMappingProxy::from(zelf.dict().clone()) + PyMappingProxy::from(zelf.dict().to_owned()) } } @@ -1206,7 +1206,7 @@ impl PyDictItems { } #[pygetset] fn mapping(zelf: PyRef) -> PyMappingProxy { - PyMappingProxy::from(zelf.dict().clone()) + PyMappingProxy::from(zelf.dict().to_owned()) } } @@ -1269,7 +1269,7 @@ impl AsNumber for PyDictItems { impl PyDictValues { #[pygetset] fn mapping(zelf: PyRef) -> PyMappingProxy { - PyMappingProxy::from(zelf.dict().clone()) + PyMappingProxy::from(zelf.dict().to_owned()) } } diff --git a/crates/vm/src/builtins/function/jit.rs b/crates/vm/src/builtins/function/jit.rs index 21d8c9c0ab..de0a528b73 100644 --- a/crates/vm/src/builtins/function/jit.rs +++ b/crates/vm/src/builtins/function/jit.rs @@ -1,6 +1,8 @@ use crate::{ AsObject, Py, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine, - builtins::{PyBaseExceptionRef, PyDictRef, PyFunction, PyStrInterned, bool_, float, int}, + builtins::{ + PyBaseExceptionRef, PyDict, PyDictRef, PyFunction, PyStrInterned, bool_, float, int, + }, bytecode::CodeFlags, convert::ToPyObject, function::FuncArgs, @@ -42,7 +44,7 @@ pub fn new_jit_error(msg: String, vm: &VirtualMachine) -> PyBaseExceptionRef { vm.new_exception_msg(jit_error, msg) } -fn get_jit_arg_type(dict: &PyDictRef, name: &str, vm: &VirtualMachine) -> PyResult { +fn get_jit_arg_type(dict: &Py, name: &str, vm: &VirtualMachine) -> PyResult { if let Some(value) = dict.get_item_opt(name, vm)? { if value.is(vm.ctx.types.int_type) { Ok(JitType::Int) diff --git a/crates/vm/src/builtins/genericalias.rs b/crates/vm/src/builtins/genericalias.rs index 494b580e56..8a7288980f 100644 --- a/crates/vm/src/builtins/genericalias.rs +++ b/crates/vm/src/builtins/genericalias.rs @@ -294,11 +294,11 @@ pub(crate) fn make_parameters(args: &Py, vm: &VirtualMachine) -> PyTupl } #[inline] -fn tuple_index(vec: &[PyObjectRef], item: &PyObjectRef) -> Option { +fn tuple_index(vec: &[PyObjectRef], item: &PyObject) -> Option { vec.iter().position(|element| element.is(item)) } -fn is_unpacked_typevartuple(arg: &PyObjectRef, vm: &VirtualMachine) -> PyResult { +fn is_unpacked_typevartuple(arg: &PyObject, vm: &VirtualMachine) -> PyResult { if arg.class().is(vm.ctx.types.type_type) { return Ok(false); } @@ -312,7 +312,7 @@ fn is_unpacked_typevartuple(arg: &PyObjectRef, vm: &VirtualMachine) -> PyResult< fn subs_tvars( obj: PyObjectRef, - params: &PyTupleRef, + params: &Py, arg_items: &[PyObjectRef], vm: &VirtualMachine, ) -> PyResult { diff --git a/crates/vm/src/builtins/list.rs b/crates/vm/src/builtins/list.rs index 0683381f38..13e8864cd1 100644 --- a/crates/vm/src/builtins/list.rs +++ b/crates/vm/src/builtins/list.rs @@ -367,8 +367,8 @@ where impl MutObjectSequenceOp for PyList { type Inner = [PyObjectRef]; - fn do_get(index: usize, inner: &[PyObjectRef]) -> Option<&PyObjectRef> { - inner.get(index) + fn do_get(index: usize, inner: &[PyObjectRef]) -> Option<&PyObject> { + inner.get(index).map(|r| r.as_ref()) } fn do_lock(&self) -> impl std::ops::Deref { diff --git a/crates/vm/src/builtins/property.rs b/crates/vm/src/builtins/property.rs index 1a2e04ee8b..41b05a6004 100644 --- a/crates/vm/src/builtins/property.rs +++ b/crates/vm/src/builtins/property.rs @@ -266,7 +266,7 @@ impl PyProperty { #[pygetset] fn __isabstractmethod__(&self, vm: &VirtualMachine) -> PyResult { // Helper to check if a method is abstract - let is_abstract = |method: &PyObjectRef| -> PyResult { + let is_abstract = |method: &PyObject| -> PyResult { match method.get_attr("__isabstractmethod__", vm) { Ok(isabstract) => isabstract.try_to_bool(vm), Err(_) => Ok(false), @@ -309,7 +309,7 @@ impl PyProperty { #[cold] fn format_property_error( &self, - obj: &PyObjectRef, + obj: &PyObject, error_type: &str, vm: &VirtualMachine, ) -> PyResult { @@ -356,7 +356,7 @@ impl Initializer for PyProperty { let mut getter_doc = false; // Helper to get doc from getter - let get_getter_doc = |fget: &PyObjectRef| -> Option { + let get_getter_doc = |fget: &PyObject| -> Option { fget.get_attr("__doc__", vm) .ok() .filter(|doc| !vm.is_none(doc)) diff --git a/crates/vm/src/builtins/type.rs b/crates/vm/src/builtins/type.rs index d014cdf015..1574335039 100644 --- a/crates/vm/src/builtins/type.rs +++ b/crates/vm/src/builtins/type.rs @@ -175,12 +175,12 @@ fn is_subtype_with_mro(a_mro: &[PyTypeRef], a: &Py, b: &Py) -> b impl PyType { pub fn new_simple_heap( name: &str, - base: &PyTypeRef, + base: &Py, ctx: &Context, ) -> Result, String> { Self::new_heap( name, - vec![base.clone()], + vec![base.to_owned()], Default::default(), Default::default(), Self::static_type().to_owned(), diff --git a/crates/vm/src/builtins/union.rs b/crates/vm/src/builtins/union.rs index 16d2b7831c..8310201a12 100644 --- a/crates/vm/src/builtins/union.rs +++ b/crates/vm/src/builtins/union.rs @@ -42,7 +42,7 @@ impl PyUnion { /// Direct access to args field, matching CPython's _Py_union_args #[inline] - pub const fn args(&self) -> &PyTupleRef { + pub fn args(&self) -> &Py { &self.args } diff --git a/crates/vm/src/cformat.rs b/crates/vm/src/cformat.rs index 507079e7de..efb3cb2acc 100644 --- a/crates/vm/src/cformat.rs +++ b/crates/vm/src/cformat.rs @@ -6,7 +6,8 @@ use crate::common::cformat::*; use crate::common::wtf8::{CodePoint, Wtf8, Wtf8Buf}; use crate::{ - AsObject, PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject, VirtualMachine, + AsObject, PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject, + VirtualMachine, builtins::{ PyBaseExceptionRef, PyByteArray, PyBytes, PyFloat, PyInt, PyStr, try_f64_to_bigint, tuple, }, @@ -207,7 +208,7 @@ fn spec_format_string( fn try_update_quantity_from_element( vm: &VirtualMachine, - element: Option<&PyObjectRef>, + element: Option<&PyObject>, ) -> PyResult { match element { Some(width_obj) => { @@ -224,7 +225,7 @@ fn try_update_quantity_from_element( fn try_conversion_flag_from_tuple( vm: &VirtualMachine, - element: Option<&PyObjectRef>, + element: Option<&PyObject>, ) -> PyResult { match element { Some(width_obj) => { @@ -254,8 +255,11 @@ fn try_update_quantity_from_tuple<'a, I: Iterator>( return Ok(()); }; let element = elements.next(); - f.insert(try_conversion_flag_from_tuple(vm, element)?); - let quantity = try_update_quantity_from_element(vm, element)?; + f.insert(try_conversion_flag_from_tuple( + vm, + element.map(|v| v.as_ref()), + )?); + let quantity = try_update_quantity_from_element(vm, element.map(|v| v.as_ref()))?; *q = Some(quantity); Ok(()) } @@ -268,7 +272,7 @@ fn try_update_precision_from_tuple<'a, I: Iterator>( let Some(CFormatPrecision::Quantity(CFormatQuantity::FromValuesTuple)) = p else { return Ok(()); }; - let quantity = try_update_quantity_from_element(vm, elements.next())?; + let quantity = try_update_quantity_from_element(vm, elements.next().map(|v| v.as_ref()))?; *p = Some(CFormatPrecision::Quantity(quantity)); Ok(()) } diff --git a/crates/vm/src/codecs.rs b/crates/vm/src/codecs.rs index dac637c396..2edb67b497 100644 --- a/crates/vm/src/codecs.rs +++ b/crates/vm/src/codecs.rs @@ -52,7 +52,7 @@ impl PyCodec { self.0 } #[inline] - pub const fn as_tuple(&self) -> &PyTupleRef { + pub fn as_tuple(&self) -> &Py { &self.0 } diff --git a/crates/vm/src/coroutine.rs b/crates/vm/src/coroutine.rs index 4e76490ed6..ebe3107cb3 100644 --- a/crates/vm/src/coroutine.rs +++ b/crates/vm/src/coroutine.rs @@ -1,7 +1,8 @@ use crate::{ - AsObject, PyObject, PyObjectRef, PyResult, VirtualMachine, + AsObject, Py, PyObject, PyObjectRef, PyResult, VirtualMachine, builtins::{PyBaseExceptionRef, PyStrRef}, common::lock::PyMutex, + exceptions::types::PyBaseException, frame::{ExecutionResult, FrameRef}, protocol::PyIterReturn, }; @@ -207,6 +208,6 @@ impl Coro { } } -pub fn is_gen_exit(exc: &PyBaseExceptionRef, vm: &VirtualMachine) -> bool { +pub fn is_gen_exit(exc: &Py, vm: &VirtualMachine) -> bool { exc.fast_isinstance(vm.ctx.exceptions.generator_exit) } diff --git a/crates/vm/src/exception_group.rs b/crates/vm/src/exception_group.rs index 8d033b2611..cd943ae1bd 100644 --- a/crates/vm/src/exception_group.rs +++ b/crates/vm/src/exception_group.rs @@ -352,12 +352,12 @@ pub(super) mod types { } // Helper functions for ExceptionGroup - fn is_base_exception_group(obj: &PyObjectRef, vm: &VirtualMachine) -> bool { + fn is_base_exception_group(obj: &PyObject, vm: &VirtualMachine) -> bool { obj.fast_isinstance(vm.ctx.exceptions.base_exception_group) } fn get_exceptions_tuple( - exc: &PyRef, + exc: &Py, vm: &VirtualMachine, ) -> PyResult> { let obj = exc @@ -376,7 +376,7 @@ pub(super) mod types { } fn get_condition_matcher( - condition: &PyObjectRef, + condition: &PyObject, vm: &VirtualMachine, ) -> PyResult { // If it's a type and subclass of BaseException @@ -409,19 +409,19 @@ pub(super) mod types { // If it's callable (but not a type) if condition.is_callable() && condition.downcast_ref::().is_none() { - return Ok(ConditionMatcher::Callable(condition.clone())); + return Ok(ConditionMatcher::Callable(condition.to_owned())); } Err(vm.new_type_error("expected a function, exception type or tuple of exception types")) } impl ConditionMatcher { - fn check(&self, exc: &PyObjectRef, vm: &VirtualMachine) -> PyResult { + fn check(&self, exc: &PyObject, vm: &VirtualMachine) -> PyResult { match self { ConditionMatcher::Type(typ) => Ok(exc.fast_isinstance(typ)), ConditionMatcher::Types(types) => Ok(types.iter().any(|t| exc.fast_isinstance(t))), ConditionMatcher::Callable(func) => { - let result = func.call((exc.clone(),), vm)?; + let result = func.call((exc.to_owned(),), vm)?; result.try_to_bool(vm) } } @@ -429,7 +429,7 @@ pub(super) mod types { } fn derive_and_copy_attributes( - orig: &PyRef, + orig: &Py, excs: Vec, vm: &VirtualMachine, ) -> PyResult { diff --git a/crates/vm/src/exceptions.rs b/crates/vm/src/exceptions.rs index 2b725085be..c02bee52c1 100644 --- a/crates/vm/src/exceptions.rs +++ b/crates/vm/src/exceptions.rs @@ -79,7 +79,7 @@ impl VirtualMachine { pub fn write_exception( &self, output: &mut W, - exc: &PyBaseExceptionRef, + exc: &Py, ) -> Result<(), W::Error> { let seen = &mut HashSet::::new(); self.write_exception_recursive(output, exc, seen) @@ -88,7 +88,7 @@ impl VirtualMachine { fn write_exception_recursive( &self, output: &mut W, - exc: &PyBaseExceptionRef, + exc: &Py, seen: &mut HashSet, ) -> Result<(), W::Error> { // This function should not be called directly, @@ -132,7 +132,7 @@ impl VirtualMachine { pub fn write_exception_inner( &self, output: &mut W, - exc: &PyBaseExceptionRef, + exc: &Py, ) -> Result<(), W::Error> { let vm = self; if let Some(tb) = exc.traceback.read().clone() { @@ -177,7 +177,7 @@ impl VirtualMachine { fn write_syntaxerror( &self, output: &mut W, - exc: &PyBaseExceptionRef, + exc: &Py, exc_type: &Py, args_repr: &[PyRef], ) -> Result<(), W::Error> { @@ -369,7 +369,7 @@ fn print_source_line( /// Print exception occurrence location from traceback element fn write_traceback_entry( output: &mut W, - tb_entry: &PyTracebackRef, + tb_entry: &Py, ) -> Result<(), W::Error> { let filename = tb_entry.frame.code.source_path.as_str(); writeln!( @@ -1053,12 +1053,12 @@ fn system_exit_code(exc: PyBaseExceptionRef) -> Option { #[cfg(feature = "serde")] pub struct SerializeException<'vm, 's> { vm: &'vm VirtualMachine, - exc: &'s PyBaseExceptionRef, + exc: &'s Py, } #[cfg(feature = "serde")] impl<'vm, 's> SerializeException<'vm, 's> { - pub fn new(vm: &'vm VirtualMachine, exc: &'s PyBaseExceptionRef) -> Self { + pub fn new(vm: &'vm VirtualMachine, exc: &'s Py) -> Self { SerializeException { vm, exc } } } diff --git a/crates/vm/src/frame.rs b/crates/vm/src/frame.rs index 4a460a9588..ad50f972ae 100644 --- a/crates/vm/src/frame.rs +++ b/crates/vm/src/frame.rs @@ -1866,14 +1866,14 @@ impl ExecutingFrame<'_> { /// This ensures proper order preservation for OrderedDict and other custom mappings. fn iterate_mapping_keys( vm: &VirtualMachine, - mapping: &PyObjectRef, + mapping: &PyObject, error_prefix: &str, mut key_handler: F, ) -> PyResult<()> where F: FnMut(PyObjectRef) -> PyResult<()>, { - let Some(keys_method) = vm.get_method(mapping.clone(), vm.ctx.intern_str("keys")) else { + let Some(keys_method) = vm.get_method(mapping.to_owned(), vm.ctx.intern_str("keys")) else { return Err(vm.new_type_error(format!("{error_prefix} must be a mapping"))); }; diff --git a/crates/vm/src/import.rs b/crates/vm/src/import.rs index c119405fe1..3f4a437c59 100644 --- a/crates/vm/src/import.rs +++ b/crates/vm/src/import.rs @@ -1,8 +1,9 @@ //! Import mechanics use crate::{ - AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, - builtins::{PyBaseExceptionRef, PyCode, list, traceback::PyTraceback}, + AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, + builtins::{PyCode, list, traceback::PyTraceback}, + exceptions::types::PyBaseException, scope::Scope, version::get_git_revision, vm::{VirtualMachine, thread}, @@ -204,7 +205,7 @@ fn remove_importlib_frames_inner( // TODO: This function should do nothing on verbose mode. // TODO: Fix this function after making PyTraceback.next mutable -pub fn remove_importlib_frames(vm: &VirtualMachine, exc: &PyBaseExceptionRef) { +pub fn remove_importlib_frames(vm: &VirtualMachine, exc: &Py) { if vm.state.settings.verbose != 0 { return; } diff --git a/crates/vm/src/object/payload.rs b/crates/vm/src/object/payload.rs index cf90387117..4b900b7caa 100644 --- a/crates/vm/src/object/payload.rs +++ b/crates/vm/src/object/payload.rs @@ -106,7 +106,7 @@ pub trait PyPayload: MaybeTraverse + PyThreadingConstraint + Sized + 'static { #[inline(never)] fn _into_ref_size_error( vm: &VirtualMachine, - cls: &PyTypeRef, + cls: &Py, exact_class: &Py, ) -> PyBaseExceptionRef { vm.new_type_error(format!( @@ -123,7 +123,7 @@ pub trait PyPayload: MaybeTraverse + PyThreadingConstraint + Sized + 'static { #[inline(never)] fn _into_ref_with_type_error( vm: &VirtualMachine, - cls: &PyTypeRef, + cls: &Py, exact_class: &Py, ) -> PyBaseExceptionRef { vm.new_type_error(format!( diff --git a/crates/vm/src/scope.rs b/crates/vm/src/scope.rs index 9311fa5c2d..4f80e9999e 100644 --- a/crates/vm/src/scope.rs +++ b/crates/vm/src/scope.rs @@ -34,7 +34,7 @@ impl Scope { Self::new(locals, globals) } - // pub fn get_locals(&self) -> &PyDictRef { + // pub fn get_locals(&self) -> &Py { // match self.locals.first() { // Some(dict) => dict, // None => &self.globals, diff --git a/crates/vm/src/sequence.rs b/crates/vm/src/sequence.rs index e75c0a6da5..6e03ad1697 100644 --- a/crates/vm/src/sequence.rs +++ b/crates/vm/src/sequence.rs @@ -12,7 +12,7 @@ use std::ops::{Deref, Range}; pub trait MutObjectSequenceOp { type Inner: ?Sized; - fn do_get(index: usize, inner: &Self::Inner) -> Option<&PyObjectRef>; + fn do_get(index: usize, inner: &Self::Inner) -> Option<&PyObject>; fn do_lock(&self) -> impl Deref; fn mut_count(&self, vm: &VirtualMachine, needle: &PyObject) -> PyResult { @@ -76,7 +76,7 @@ pub trait MutObjectSequenceOp { } borrower = Some(guard); } else { - let elem = elem.clone(); + let elem = elem.to_owned(); drop(guard); if elem.rich_compare_bool(needle, PyComparisonOp::Eq, vm)? { diff --git a/crates/vm/src/stdlib/builtins.rs b/crates/vm/src/stdlib/builtins.rs index 542476d68c..442bb79b94 100644 --- a/crates/vm/src/stdlib/builtins.rs +++ b/crates/vm/src/stdlib/builtins.rs @@ -10,7 +10,7 @@ mod builtins { use std::io::IsTerminal; use crate::{ - AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, + AsObject, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::{ PyByteArray, PyBytes, PyDictRef, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, enumerate::PyReverseSequenceIterator, @@ -261,7 +261,7 @@ mod builtins { func_name: &'static str, ) -> PyResult { fn validate_globals_dict( - globals: &PyObjectRef, + globals: &PyObject, vm: &VirtualMachine, func_name: &'static str, ) -> PyResult<()> { diff --git a/crates/vm/src/stdlib/collections.rs b/crates/vm/src/stdlib/collections.rs index 32596b6538..eae56968cb 100644 --- a/crates/vm/src/stdlib/collections.rs +++ b/crates/vm/src/stdlib/collections.rs @@ -422,8 +422,8 @@ mod _collections { impl MutObjectSequenceOp for PyDeque { type Inner = VecDeque; - fn do_get(index: usize, inner: &Self::Inner) -> Option<&PyObjectRef> { - inner.get(index) + fn do_get(index: usize, inner: &Self::Inner) -> Option<&PyObject> { + inner.get(index).map(|r| r.as_ref()) } fn do_lock(&self) -> impl std::ops::Deref { diff --git a/crates/vm/src/stdlib/ctypes.rs b/crates/vm/src/stdlib/ctypes.rs index 70aee7378d..ebe2d16ffb 100644 --- a/crates/vm/src/stdlib/ctypes.rs +++ b/crates/vm/src/stdlib/ctypes.rs @@ -53,7 +53,7 @@ pub(crate) mod _ctypes { use crate::convert::ToPyObject; use crate::function::{Either, FuncArgs, OptionalArg}; use crate::stdlib::ctypes::library; - use crate::{AsObject, PyObjectRef, PyPayload, PyResult, VirtualMachine}; + use crate::{AsObject, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine}; use crossbeam_utils::atomic::AtomicCell; use std::ffi::{ c_double, c_float, c_int, c_long, c_longlong, c_schar, c_short, c_uchar, c_uint, c_ulong, @@ -349,7 +349,7 @@ pub(crate) mod _ctypes { const SIMPLE_TYPE_CHARS: &str = "cbBhHiIlLdfguzZPqQ?O"; pub fn new_simple_type( - cls: Either<&PyObjectRef, &PyTypeRef>, + cls: Either<&PyObject, &PyTypeRef>, vm: &VirtualMachine, ) -> PyResult { let cls = match cls { diff --git a/crates/vm/src/stdlib/ctypes/base.rs b/crates/vm/src/stdlib/ctypes/base.rs index a4664ad367..e45ff0b3b7 100644 --- a/crates/vm/src/stdlib/ctypes/base.rs +++ b/crates/vm/src/stdlib/ctypes/base.rs @@ -5,7 +5,9 @@ use crate::function::{ArgBytesLike, Either, FuncArgs, KwArgs, OptionalArg}; use crate::protocol::{BufferDescriptor, BufferMethods, PyBuffer, PyNumberMethods}; use crate::stdlib::ctypes::_ctypes::new_simple_type; use crate::types::{AsBuffer, AsNumber, Constructor}; -use crate::{AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine}; +use crate::{ + AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, +}; use crossbeam_utils::atomic::AtomicCell; use num_traits::ToPrimitive; use rustpython_common::lock::PyRwLock; @@ -46,19 +48,19 @@ pub fn ffi_type_from_str(_type_: &str) -> Option { } #[allow(dead_code)] -fn set_primitive(_type_: &str, value: &PyObjectRef, vm: &VirtualMachine) -> PyResult { +fn set_primitive(_type_: &str, value: &PyObject, vm: &VirtualMachine) -> PyResult { match _type_ { "c" => { if value - .clone() + .to_owned() .downcast_exact::(vm) .is_ok_and(|v| v.len() == 1) || value - .clone() + .to_owned() .downcast_exact::(vm) .is_ok_and(|v| v.len() == 1) || value - .clone() + .to_owned() .downcast_exact::(vm) .map_or(Ok(false), |v| { let n = v.as_bigint().to_i64(); @@ -69,7 +71,7 @@ fn set_primitive(_type_: &str, value: &PyObjectRef, vm: &VirtualMachine) -> PyRe } })? { - Ok(value.clone()) + Ok(value.to_owned()) } else { Err(vm.new_type_error("one character bytes, bytearray or integer expected")) } @@ -77,7 +79,7 @@ fn set_primitive(_type_: &str, value: &PyObjectRef, vm: &VirtualMachine) -> PyRe "u" => { if let Ok(b) = value.str(vm).map(|v| v.to_string().chars().count() == 1) { if b { - Ok(value.clone()) + Ok(value.to_owned()) } else { Err(vm.new_type_error("one character unicode string expected")) } @@ -89,8 +91,8 @@ fn set_primitive(_type_: &str, value: &PyObjectRef, vm: &VirtualMachine) -> PyRe } } "b" | "h" | "H" | "i" | "I" | "l" | "q" | "L" | "Q" => { - if value.clone().downcast_exact::(vm).is_ok() { - Ok(value.clone()) + if value.to_owned().downcast_exact::(vm).is_ok() { + Ok(value.to_owned()) } else { Err(vm.new_type_error(format!( "an integer is required (got type {})", @@ -100,30 +102,30 @@ fn set_primitive(_type_: &str, value: &PyObjectRef, vm: &VirtualMachine) -> PyRe } "f" | "d" | "g" => { // float allows int - if value.clone().downcast_exact::(vm).is_ok() - || value.clone().downcast_exact::(vm).is_ok() + if value.to_owned().downcast_exact::(vm).is_ok() + || value.to_owned().downcast_exact::(vm).is_ok() { - Ok(value.clone()) + Ok(value.to_owned()) } else { Err(vm.new_type_error(format!("must be real number, not {}", value.class().name()))) } } "?" => Ok(PyObjectRef::from( - vm.ctx.new_bool(value.clone().try_to_bool(vm)?), + vm.ctx.new_bool(value.to_owned().try_to_bool(vm)?), )), "B" => { - if value.clone().downcast_exact::(vm).is_ok() { + if value.to_owned().downcast_exact::(vm).is_ok() { // Store as-is, conversion to unsigned happens in the getter - Ok(value.clone()) + Ok(value.to_owned()) } else { Err(vm.new_type_error(format!("int expected instead of {}", value.class().name()))) } } "z" => { - if value.clone().downcast_exact::(vm).is_ok() - || value.clone().downcast_exact::(vm).is_ok() + if value.to_owned().downcast_exact::(vm).is_ok() + || value.to_owned().downcast_exact::(vm).is_ok() { - Ok(value.clone()) + Ok(value.to_owned()) } else { Err(vm.new_type_error(format!( "bytes or integer address expected instead of {} instance", @@ -132,8 +134,8 @@ fn set_primitive(_type_: &str, value: &PyObjectRef, vm: &VirtualMachine) -> PyRe } } "Z" => { - if value.clone().downcast_exact::(vm).is_ok() { - Ok(value.clone()) + if value.to_owned().downcast_exact::(vm).is_ok() { + Ok(value.to_owned()) } else { Err(vm.new_type_error(format!( "unicode string or integer address expected instead of {} instance", @@ -143,10 +145,10 @@ fn set_primitive(_type_: &str, value: &PyObjectRef, vm: &VirtualMachine) -> PyRe } _ => { // "P" - if value.clone().downcast_exact::(vm).is_ok() - || value.clone().downcast_exact::(vm).is_ok() + if value.to_owned().downcast_exact::(vm).is_ok() + || value.to_owned().downcast_exact::(vm).is_ok() { - Ok(value.clone()) + Ok(value.to_owned()) } else { Err(vm.new_type_error("cannot be converted to pointer")) } @@ -437,7 +439,7 @@ impl Debug for PyCSimple { fn value_to_bytes_endian( _type_: &str, - value: &PyObjectRef, + value: &PyObject, swapped: bool, vm: &VirtualMachine, ) -> Vec { @@ -598,7 +600,7 @@ fn value_to_bytes_endian( } "?" => { // c_bool (1 byte) - if let Ok(b) = value.clone().try_to_bool(vm) { + if let Ok(b) = value.to_owned().try_to_bool(vm) { return vec![if b { 1 } else { 0 }]; } vec![0] diff --git a/crates/vm/src/stdlib/ctypes/field.rs b/crates/vm/src/stdlib/ctypes/field.rs index 659255f332..ea57d68065 100644 --- a/crates/vm/src/stdlib/ctypes/field.rs +++ b/crates/vm/src/stdlib/ctypes/field.rs @@ -1,7 +1,7 @@ use crate::builtins::PyType; use crate::function::PySetterValue; use crate::types::{GetDescriptor, Representable}; -use crate::{AsObject, Py, PyObjectRef, PyResult, VirtualMachine}; +use crate::{AsObject, Py, PyObject, PyObjectRef, PyResult, VirtualMachine}; use num_traits::ToPrimitive; use super::structure::PyCStructure; @@ -152,7 +152,7 @@ impl PyCField { } /// Convert a Python value to bytes - fn value_to_bytes(value: &PyObjectRef, size: usize, vm: &VirtualMachine) -> PyResult> { + fn value_to_bytes(value: &PyObject, size: usize, vm: &VirtualMachine) -> PyResult> { if let Ok(int_val) = value.try_int(vm) { let i = int_val.as_bigint(); match size { diff --git a/crates/vm/src/stdlib/ctypes/structure.rs b/crates/vm/src/stdlib/ctypes/structure.rs index f32d6865cb..ca67a2fe7d 100644 --- a/crates/vm/src/stdlib/ctypes/structure.rs +++ b/crates/vm/src/stdlib/ctypes/structure.rs @@ -7,7 +7,7 @@ use crate::function::FuncArgs; use crate::protocol::{BufferDescriptor, BufferMethods, PyBuffer, PyNumberMethods}; use crate::stdlib::ctypes::_ctypes::get_size; use crate::types::{AsBuffer, AsNumber, Constructor}; -use crate::{AsObject, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine}; +use crate::{AsObject, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine}; use indexmap::IndexMap; use num_traits::ToPrimitive; use rustpython_common::lock::PyRwLock; @@ -109,7 +109,7 @@ impl PyCStructType { } /// Get the size of a ctypes type - fn get_field_size(field_type: &PyObjectRef, vm: &VirtualMachine) -> PyResult { + fn get_field_size(field_type: &PyObject, vm: &VirtualMachine) -> PyResult { // Try to get _type_ attribute for simple types if let Some(size) = field_type .get_attr("_type_", vm) @@ -139,7 +139,7 @@ impl PyCStructType { } /// Get the alignment of a ctypes type - fn get_field_align(field_type: &PyObjectRef, vm: &VirtualMachine) -> usize { + fn get_field_align(field_type: &PyObject, vm: &VirtualMachine) -> usize { // Try to get _type_ attribute for simple types if let Some(align) = field_type .get_attr("_type_", vm) diff --git a/crates/vm/src/stdlib/ctypes/union.rs b/crates/vm/src/stdlib/ctypes/union.rs index e6873e8750..308a5e4e98 100644 --- a/crates/vm/src/stdlib/ctypes/union.rs +++ b/crates/vm/src/stdlib/ctypes/union.rs @@ -7,7 +7,7 @@ use crate::function::FuncArgs; use crate::protocol::{BufferDescriptor, BufferMethods, PyBuffer as ProtocolPyBuffer}; use crate::stdlib::ctypes::_ctypes::get_size; use crate::types::{AsBuffer, Constructor}; -use crate::{AsObject, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine}; +use crate::{AsObject, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine}; use num_traits::ToPrimitive; use rustpython_common::lock::PyRwLock; @@ -90,7 +90,7 @@ impl PyCUnionType { Ok(()) } - fn get_field_size(field_type: &PyObjectRef, vm: &VirtualMachine) -> PyResult { + fn get_field_size(field_type: &PyObject, vm: &VirtualMachine) -> PyResult { if let Some(size) = field_type .get_attr("_type_", vm) .ok() diff --git a/crates/vm/src/stdlib/typevar.rs b/crates/vm/src/stdlib/typevar.rs index e8cc407da1..65249bfd07 100644 --- a/crates/vm/src/stdlib/typevar.rs +++ b/crates/vm/src/stdlib/typevar.rs @@ -44,7 +44,7 @@ fn caller(vm: &VirtualMachine) -> Option { /// Set __module__ attribute for an object based on the caller's module. /// This follows CPython's behavior for TypeVar and similar objects. -fn set_module_from_caller(obj: &PyObjectRef, vm: &VirtualMachine) -> PyResult<()> { +fn set_module_from_caller(obj: &PyObject, vm: &VirtualMachine) -> PyResult<()> { // Note: CPython gets module from frame->f_funcobj, but RustPython's Frame // architecture is different - we use globals['__name__'] instead if let Some(module_name) = caller(vm) { @@ -1006,15 +1006,15 @@ pub fn set_typeparam_default( ) -> PyResult { // Inner function to handle common pattern of setting evaluate_default fn try_set_default( - obj: &PyObjectRef, - evaluate_default: &PyObjectRef, + obj: &PyObject, + evaluate_default: &PyObject, get_field: impl FnOnce(&T) -> &PyMutex, ) -> bool where T: PyPayload, { if let Some(typed_obj) = obj.downcast_ref::() { - *get_field(typed_obj).lock() = evaluate_default.clone(); + *get_field(typed_obj).lock() = evaluate_default.to_owned(); true } else { false diff --git a/crates/vm/src/suggestion.rs b/crates/vm/src/suggestion.rs index 2cc935873c..866deb668e 100644 --- a/crates/vm/src/suggestion.rs +++ b/crates/vm/src/suggestion.rs @@ -2,9 +2,9 @@ //! This is used during tracebacks. use crate::{ - AsObject, Py, PyObjectRef, VirtualMachine, + AsObject, Py, PyObject, PyObjectRef, VirtualMachine, builtins::{PyStr, PyStrRef}, - exceptions::types::PyBaseExceptionRef, + exceptions::types::PyBaseException, sliceable::SliceableSequenceOp, }; use rustpython_common::str::levenshtein::{MOVE_COST, levenshtein_distance}; @@ -14,7 +14,7 @@ const MAX_CANDIDATE_ITEMS: usize = 750; pub fn calculate_suggestions<'a>( dir_iter: impl ExactSizeIterator, - name: &PyObjectRef, + name: &PyObject, ) -> Option { if dir_iter.len() >= MAX_CANDIDATE_ITEMS { return None; @@ -47,7 +47,7 @@ pub fn calculate_suggestions<'a>( suggestion.map(|r| r.to_owned()) } -pub fn offer_suggestions(exc: &PyBaseExceptionRef, vm: &VirtualMachine) -> Option { +pub fn offer_suggestions(exc: &Py, vm: &VirtualMachine) -> Option { if exc.class().is(vm.ctx.exceptions.attribute_error) { let name = exc.as_object().get_attr("name", vm).unwrap(); let obj = exc.as_object().get_attr("obj", vm).unwrap(); diff --git a/crates/vm/src/vm/context.rs b/crates/vm/src/vm/context.rs index fbda71dc1f..486c1861fb 100644 --- a/crates/vm/src/vm/context.rs +++ b/crates/vm/src/vm/context.rs @@ -62,9 +62,9 @@ macro_rules! declare_const_name { } impl ConstName { - unsafe fn new(pool: &StringPool, typ: &PyTypeRef) -> Self { + unsafe fn new(pool: &StringPool, typ: &Py) -> Self { Self { - $($name: unsafe { pool.intern(declare_const_name!(@string $name $($s)?), typ.clone()) },)* + $($name: unsafe { pool.intern(declare_const_name!(@string $name $($s)?), typ.to_owned()) },)* } } } @@ -317,7 +317,7 @@ impl Context { ); let string_pool = StringPool::default(); - let names = unsafe { ConstName::new(&string_pool, &types.str_type.to_owned()) }; + let names = unsafe { ConstName::new(&string_pool, types.str_type) }; let slot_new_wrapper = PyMethodDef::new_const( names.__new__.as_str(), diff --git a/crates/vm/src/vm/mod.rs b/crates/vm/src/vm/mod.rs index fd37b2494d..4574b2de37 100644 --- a/crates/vm/src/vm/mod.rs +++ b/crates/vm/src/vm/mod.rs @@ -23,6 +23,7 @@ use crate::{ codecs::CodecsRegistry, common::{hash::HashSecret, lock::PyMutex, rc::PyRc}, convert::ToPyObject, + exceptions::types::PyBaseException, frame::{ExecutionResult, Frame, FrameRef}, frozen::FrozenModule, function::{ArgMapping, FuncArgs, PySetterValue}, @@ -728,7 +729,7 @@ impl VirtualMachine { pub fn set_attribute_error_context( &self, - exc: &PyBaseExceptionRef, + exc: &Py, obj: PyObjectRef, name: PyStrRef, ) { @@ -814,7 +815,7 @@ impl VirtualMachine { drop(prev); } - pub(crate) fn contextualize_exception(&self, exception: &PyBaseExceptionRef) { + pub(crate) fn contextualize_exception(&self, exception: &Py) { if let Some(context_exc) = self.topmost_exception() && !context_exc.is(exception) { diff --git a/crates/vm/src/warn.rs b/crates/vm/src/warn.rs index 6480f77843..b632495eb4 100644 --- a/crates/vm/src/warn.rs +++ b/crates/vm/src/warn.rs @@ -1,5 +1,5 @@ use crate::{ - AsObject, Context, Py, PyObjectRef, PyResult, VirtualMachine, + AsObject, Context, Py, PyObject, PyObjectRef, PyResult, VirtualMachine, builtins::{ PyDictRef, PyListRef, PyStr, PyStrInterned, PyStrRef, PyTuple, PyTupleRef, PyTypeRef, }, @@ -38,7 +38,7 @@ impl WarningsState { } } -fn check_matched(obj: &PyObjectRef, arg: &PyObjectRef, vm: &VirtualMachine) -> PyResult { +fn check_matched(obj: &PyObject, arg: &PyObject, vm: &VirtualMachine) -> PyResult { if obj.class().is(vm.ctx.types.none_type) { return Ok(true); } diff --git a/crates/wasm/src/convert.rs b/crates/wasm/src/convert.rs index d1821f2e73..f84b0d4623 100644 --- a/crates/wasm/src/convert.rs +++ b/crates/wasm/src/convert.rs @@ -4,8 +4,8 @@ use crate::js_module; use crate::vm_class::{WASMVirtualMachine, stored_vm_from_wasm}; use js_sys::{Array, ArrayBuffer, Object, Promise, Reflect, SyntaxError, Uint8Array}; use rustpython_vm::{ - AsObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine, - builtins::PyBaseExceptionRef, + AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine, + builtins::{PyBaseException, PyBaseExceptionRef}, compiler::{CompileError, ParseError, parser::LexicalErrorType, parser::ParseErrorType}, exceptions, function::{ArgBytesLike, FuncArgs}, @@ -32,7 +32,7 @@ extern "C" { fn new(info: JsValue) -> PyError; } -pub fn py_err_to_js_err(vm: &VirtualMachine, py_err: &PyBaseExceptionRef) -> JsValue { +pub fn py_err_to_js_err(vm: &VirtualMachine, py_err: &Py) -> JsValue { let js_err = vm.try_class("_js", "JSError").ok(); let js_arg = if js_err.is_some_and(|js_err| py_err.fast_isinstance(&js_err)) { py_err.get_arg(0) diff --git a/crates/wasm/src/js_module.rs b/crates/wasm/src/js_module.rs index 1d8ca0961c..d4f623da9f 100644 --- a/crates/wasm/src/js_module.rs +++ b/crates/wasm/src/js_module.rs @@ -612,8 +612,7 @@ mod _js { fn js_error(vm: &VirtualMachine) -> PyTypeRef { let ctx = &vm.ctx; let js_error = PyRef::leak( - PyType::new_simple_heap("JSError", &vm.ctx.exceptions.exception_type.to_owned(), ctx) - .unwrap(), + PyType::new_simple_heap("JSError", vm.ctx.exceptions.exception_type, ctx).unwrap(), ); extend_class!(ctx, js_error, { "value" => ctx.new_readonly_getset("value", js_error, |exc: PyBaseExceptionRef| exc.get_arg(0)),