Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove useless &PyRef
  • Loading branch information
youknowone committed Dec 17, 2025
commit 905c706c732f3144ba3e6adf6270e7e6a1f97803
5 changes: 3 additions & 2 deletions crates/stdlib/src/openssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<PyBaseException>,
ssl_ptr: *const sys::SSL,
vm: &VirtualMachine,
) {
Expand Down
6 changes: 3 additions & 3 deletions crates/stdlib/src/scproxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -74,7 +74,7 @@ mod _scproxy {

let result = vm.ctx.new_dict();

let set_proxy = |result: &PyDictRef,
let set_proxy = |result: &Py<PyDict>,
proto: &str,
enabled_key: CFStringRef,
host_key: CFStringRef,
Expand Down
8 changes: 4 additions & 4 deletions crates/stdlib/src/ssl/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -984,7 +984,7 @@ pub(super) fn create_client_config(options: ClientConfigOptions) -> Result<Clien
}

/// Helper function - check if error is BlockingIOError
pub(super) fn is_blocking_io_error(err: &PyBaseExceptionRef, vm: &VirtualMachine) -> bool {
pub(super) fn is_blocking_io_error(err: &Py<PyBaseException>, vm: &VirtualMachine) -> bool {
err.fast_isinstance(vm.ctx.exceptions.blocking_io_error)
}

Expand Down Expand Up @@ -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<PyBaseException>, vm: &VirtualMachine) -> bool {
use rustpython_vm::stdlib::errno::errors;

// Check for ConnectionAbortedError, ConnectionResetError (Python exception types)
Expand Down
10 changes: 5 additions & 5 deletions crates/vm/src/builtins/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PyDict>;
fn item(vm: &VirtualMachine, key: PyObjectRef, value: PyObjectRef) -> PyObjectRef;

#[pymethod]
Expand Down Expand Up @@ -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<PyDict> {
&self.dict
}

Expand Down Expand Up @@ -1142,7 +1142,7 @@ impl PyDictKeys {

#[pygetset]
fn mapping(zelf: PyRef<Self>) -> PyMappingProxy {
PyMappingProxy::from(zelf.dict().clone())
PyMappingProxy::from(zelf.dict().to_owned())
}
}

Expand Down Expand Up @@ -1206,7 +1206,7 @@ impl PyDictItems {
}
#[pygetset]
fn mapping(zelf: PyRef<Self>) -> PyMappingProxy {
PyMappingProxy::from(zelf.dict().clone())
PyMappingProxy::from(zelf.dict().to_owned())
}
}

Expand Down Expand Up @@ -1269,7 +1269,7 @@ impl AsNumber for PyDictItems {
impl PyDictValues {
#[pygetset]
fn mapping(zelf: PyRef<Self>) -> PyMappingProxy {
PyMappingProxy::from(zelf.dict().clone())
PyMappingProxy::from(zelf.dict().to_owned())
}
}

Expand Down
6 changes: 4 additions & 2 deletions crates/vm/src/builtins/function/jit.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<JitType> {
fn get_jit_arg_type(dict: &Py<PyDict>, name: &str, vm: &VirtualMachine) -> PyResult<JitType> {
if let Some(value) = dict.get_item_opt(name, vm)? {
if value.is(vm.ctx.types.int_type) {
Ok(JitType::Int)
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/genericalias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ fn is_unpacked_typevartuple(arg: &PyObject, vm: &VirtualMachine) -> PyResult<boo

fn subs_tvars(
obj: PyObjectRef,
params: &PyTupleRef,
params: &Py<PyTuple>,
arg_items: &[PyObjectRef],
vm: &VirtualMachine,
) -> PyResult {
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PyTuple> {
&self.args
}

Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl PyCodec {
self.0
}
#[inline]
pub const fn as_tuple(&self) -> &PyTupleRef {
pub fn as_tuple(&self) -> &Py<PyTuple> {
&self.0
}

Expand Down
5 changes: 3 additions & 2 deletions crates/vm/src/coroutine.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down Expand Up @@ -207,6 +208,6 @@ impl Coro {
}
}

pub fn is_gen_exit(exc: &PyBaseExceptionRef, vm: &VirtualMachine) -> bool {
pub fn is_gen_exit(exc: &Py<PyBaseException>, vm: &VirtualMachine) -> bool {
exc.fast_isinstance(vm.ctx.exceptions.generator_exit)
}
4 changes: 2 additions & 2 deletions crates/vm/src/exception_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ pub(super) mod types {
}

fn get_exceptions_tuple(
exc: &PyRef<PyBaseException>,
exc: &Py<PyBaseException>,
vm: &VirtualMachine,
) -> PyResult<Vec<PyObjectRef>> {
let obj = exc
Expand Down Expand Up @@ -429,7 +429,7 @@ pub(super) mod types {
}

fn derive_and_copy_attributes(
orig: &PyRef<PyBaseException>,
orig: &Py<PyBaseException>,
excs: Vec<PyObjectRef>,
vm: &VirtualMachine,
) -> PyResult<PyObjectRef> {
Expand Down
14 changes: 7 additions & 7 deletions crates/vm/src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl VirtualMachine {
pub fn write_exception<W: Write>(
&self,
output: &mut W,
exc: &PyBaseExceptionRef,
exc: &Py<PyBaseException>,
) -> Result<(), W::Error> {
let seen = &mut HashSet::<usize>::new();
self.write_exception_recursive(output, exc, seen)
Expand All @@ -88,7 +88,7 @@ impl VirtualMachine {
fn write_exception_recursive<W: Write>(
&self,
output: &mut W,
exc: &PyBaseExceptionRef,
exc: &Py<PyBaseException>,
seen: &mut HashSet<usize>,
) -> Result<(), W::Error> {
// This function should not be called directly,
Expand Down Expand Up @@ -132,7 +132,7 @@ impl VirtualMachine {
pub fn write_exception_inner<W: Write>(
&self,
output: &mut W,
exc: &PyBaseExceptionRef,
exc: &Py<PyBaseException>,
) -> Result<(), W::Error> {
let vm = self;
if let Some(tb) = exc.traceback.read().clone() {
Expand Down Expand Up @@ -177,7 +177,7 @@ impl VirtualMachine {
fn write_syntaxerror<W: Write>(
&self,
output: &mut W,
exc: &PyBaseExceptionRef,
exc: &Py<PyBaseException>,
exc_type: &Py<PyType>,
args_repr: &[PyRef<PyStr>],
) -> Result<(), W::Error> {
Expand Down Expand Up @@ -369,7 +369,7 @@ fn print_source_line<W: Write>(
/// Print exception occurrence location from traceback element
fn write_traceback_entry<W: Write>(
output: &mut W,
tb_entry: &PyTracebackRef,
tb_entry: &Py<PyTraceback>,
) -> Result<(), W::Error> {
let filename = tb_entry.frame.code.source_path.as_str();
writeln!(
Expand Down Expand Up @@ -1053,12 +1053,12 @@ fn system_exit_code(exc: PyBaseExceptionRef) -> Option<PyObjectRef> {
#[cfg(feature = "serde")]
pub struct SerializeException<'vm, 's> {
vm: &'vm VirtualMachine,
exc: &'s PyBaseExceptionRef,
exc: &'s Py<PyBaseException>,
}

#[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<PyBaseException>) -> Self {
SerializeException { vm, exc }
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/vm/src/import.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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<PyBaseException>) {
if vm.state.settings.verbose != 0 {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Scope {
Self::new(locals, globals)
}

// pub fn get_locals(&self) -> &PyDictRef {
// pub fn get_locals(&self) -> &Py<PyDict> {
// match self.locals.first() {
// Some(dict) => dict,
// None => &self.globals,
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::{
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};
Expand Down Expand Up @@ -47,7 +47,7 @@ pub fn calculate_suggestions<'a>(
suggestion.map(|r| r.to_owned())
}

pub fn offer_suggestions(exc: &PyBaseExceptionRef, vm: &VirtualMachine) -> Option<PyStrRef> {
pub fn offer_suggestions(exc: &Py<PyBaseException>, vm: &VirtualMachine) -> Option<PyStrRef> {
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();
Expand Down
5 changes: 3 additions & 2 deletions crates/vm/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -728,7 +729,7 @@ impl VirtualMachine {

pub fn set_attribute_error_context(
&self,
exc: &PyBaseExceptionRef,
exc: &Py<PyBaseException>,
obj: PyObjectRef,
name: PyStrRef,
) {
Expand Down Expand Up @@ -814,7 +815,7 @@ impl VirtualMachine {
drop(prev);
}

pub(crate) fn contextualize_exception(&self, exception: &PyBaseExceptionRef) {
pub(crate) fn contextualize_exception(&self, exception: &Py<PyBaseException>) {
if let Some(context_exc) = self.topmost_exception()
&& !context_exc.is(exception)
{
Expand Down
6 changes: 3 additions & 3 deletions crates/wasm/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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<PyBaseException>) -> 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)
Expand Down
3 changes: 1 addition & 2 deletions crates/wasm/src/js_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
Loading