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
Next Next commit
Remove useless &PyObjectRef
  • Loading branch information
youknowone committed Dec 17, 2025
commit 477af6dd8c946e9f4f38d0f2389af69ec079c624
18 changes: 8 additions & 10 deletions crates/stdlib/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<u8> {
fn parse_delimiter_from_obj(vm: &VirtualMachine, obj: &PyObject) -> PyResult<u8> {
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"#;
Expand All @@ -148,7 +149,7 @@ mod _csv {
})
}
}
fn parse_quotechar_from_obj(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<Option<u8>> {
fn parse_quotechar_from_obj(vm: &VirtualMachine, obj: &PyObject) -> PyResult<Option<u8>> {
match_class!(match obj.get_attr("quotechar", vm)? {
s @ PyStr => {
Ok(Some(s.as_str().bytes().exactly_one().map_err(|_| {
Expand All @@ -169,7 +170,7 @@ mod _csv {
}
})
}
fn parse_escapechar_from_obj(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<Option<u8>> {
fn parse_escapechar_from_obj(vm: &VirtualMachine, obj: &PyObject) -> PyResult<Option<u8>> {
match_class!(match obj.get_attr("escapechar", vm)? {
s @ PyStr => {
Ok(Some(s.as_str().bytes().exactly_one().map_err(|_| {
Expand All @@ -191,10 +192,7 @@ mod _csv {
}
})
}
fn prase_lineterminator_from_obj(
vm: &VirtualMachine,
obj: &PyObjectRef,
) -> PyResult<Terminator> {
fn prase_lineterminator_from_obj(vm: &VirtualMachine, obj: &PyObject) -> PyResult<Terminator> {
match_class!(match obj.get_attr("lineterminator", vm)? {
s @ PyStr => {
Ok(if s.as_bytes().eq(b"\r\n") {
Expand All @@ -217,7 +215,7 @@ mod _csv {
}
})
}
fn prase_quoting_from_obj(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<QuoteStyle> {
fn prase_quoting_from_obj(vm: &VirtualMachine, obj: &PyObject) -> PyResult<QuoteStyle> {
match_class!(match obj.get_attr("quoting", vm)? {
i @ PyInt => {
Ok(i.try_to_primitive::<isize>(vm)?.try_into().map_err(|_| {
Expand Down
14 changes: 7 additions & 7 deletions crates/stdlib/src/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
Expand Down Expand Up @@ -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<String> {
if let Ok(s) = PyStrRef::try_from_object(vm, arg.clone()) {
fn parse_path_arg(arg: &PyObject, vm: &VirtualMachine) -> PyResult<String> {
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 {
Expand Down Expand Up @@ -2279,10 +2279,10 @@ mod _ssl {
}

/// Helper: Parse cadata argument (str or bytes)
fn parse_cadata_arg(&self, arg: &PyObjectRef, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
if let Ok(s) = PyStrRef::try_from_object(vm, arg.clone()) {
fn parse_cadata_arg(&self, arg: &PyObject, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
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()))
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/builtins/builtin_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/builtins/genericalias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ pub(crate) fn make_parameters(args: &Py<PyTuple>, vm: &VirtualMachine) -> PyTupl
}

#[inline]
fn tuple_index(vec: &[PyObjectRef], item: &PyObjectRef) -> Option<usize> {
fn tuple_index(vec: &[PyObjectRef], item: &PyObject) -> Option<usize> {
vec.iter().position(|element| element.is(item))
}

fn is_unpacked_typevartuple(arg: &PyObjectRef, vm: &VirtualMachine) -> PyResult<bool> {
fn is_unpacked_typevartuple(arg: &PyObject, vm: &VirtualMachine) -> PyResult<bool> {
if arg.class().is(vm.ctx.types.type_type) {
return Ok(false);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/builtins/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Target = [PyObjectRef]> {
Expand Down
6 changes: 3 additions & 3 deletions crates/vm/src/builtins/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
let is_abstract = |method: &PyObject| -> PyResult<bool> {
match method.get_attr("__isabstractmethod__", vm) {
Ok(isabstract) => isabstract.try_to_bool(vm),
Err(_) => Ok(false),
Expand Down Expand Up @@ -309,7 +309,7 @@ impl PyProperty {
#[cold]
fn format_property_error(
&self,
obj: &PyObjectRef,
obj: &PyObject,
error_type: &str,
vm: &VirtualMachine,
) -> PyResult<String> {
Expand Down Expand Up @@ -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<PyObjectRef> {
let get_getter_doc = |fget: &PyObject| -> Option<PyObjectRef> {
fget.get_attr("__doc__", vm)
.ok()
.filter(|doc| !vm.is_none(doc))
Expand Down
16 changes: 10 additions & 6 deletions crates/vm/src/cformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -207,7 +208,7 @@ fn spec_format_string(

fn try_update_quantity_from_element(
vm: &VirtualMachine,
element: Option<&PyObjectRef>,
element: Option<&PyObject>,
) -> PyResult<CFormatQuantity> {
match element {
Some(width_obj) => {
Expand All @@ -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<CConversionFlags> {
match element {
Some(width_obj) => {
Expand Down Expand Up @@ -254,8 +255,11 @@ fn try_update_quantity_from_tuple<'a, I: Iterator<Item = &'a PyObjectRef>>(
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(())
}
Expand All @@ -268,7 +272,7 @@ fn try_update_precision_from_tuple<'a, I: Iterator<Item = &'a PyObjectRef>>(
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(())
}
Expand Down
10 changes: 5 additions & 5 deletions crates/vm/src/exception_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ 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)
}

Expand All @@ -376,7 +376,7 @@ pub(super) mod types {
}

fn get_condition_matcher(
condition: &PyObjectRef,
condition: &PyObject,
vm: &VirtualMachine,
) -> PyResult<ConditionMatcher> {
// If it's a type and subclass of BaseException
Expand Down Expand Up @@ -409,19 +409,19 @@ pub(super) mod types {

// If it's callable (but not a type)
if condition.is_callable() && condition.downcast_ref::<PyType>().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<bool> {
fn check(&self, exc: &PyObject, vm: &VirtualMachine) -> PyResult<bool> {
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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1866,14 +1866,14 @@ impl ExecutingFrame<'_> {
/// This ensures proper order preservation for OrderedDict and other custom mappings.
fn iterate_mapping_keys<F>(
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")));
};

Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Target = Self::Inner>;

fn mut_count(&self, vm: &VirtualMachine, needle: &PyObject) -> PyResult<usize> {
Expand Down Expand Up @@ -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)? {
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/stdlib/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -261,7 +261,7 @@ mod builtins {
func_name: &'static str,
) -> PyResult<crate::scope::Scope> {
fn validate_globals_dict(
globals: &PyObjectRef,
globals: &PyObject,
vm: &VirtualMachine,
func_name: &'static str,
) -> PyResult<()> {
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/stdlib/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ mod _collections {
impl MutObjectSequenceOp for PyDeque {
type Inner = VecDeque<PyObjectRef>;

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<Target = Self::Inner> {
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/stdlib/ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<PyCSimple> {
let cls = match cls {
Expand Down
Loading