Skip to content

Commit 905c706

Browse files
committed
Remove useless &PyRef
1 parent 477af6d commit 905c706

File tree

17 files changed

+48
-43
lines changed

17 files changed

+48
-43
lines changed

crates/stdlib/src/openssl.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ mod _ssl {
5656
vm::{
5757
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
5858
builtins::{
59-
PyBaseExceptionRef, PyBytesRef, PyListRef, PyOSError, PyStrRef, PyTypeRef, PyWeak,
59+
PyBaseException, PyBaseExceptionRef, PyBytesRef, PyListRef, PyOSError, PyStrRef,
60+
PyTypeRef, PyWeak,
6061
},
6162
class_or_notimplemented,
6263
convert::ToPyException,
@@ -3351,7 +3352,7 @@ mod _ssl {
33513352

33523353
// Helper function to set verify_code and verify_message on SSLCertVerificationError
33533354
fn set_verify_error_info(
3354-
exc: &PyBaseExceptionRef,
3355+
exc: &Py<PyBaseException>,
33553356
ssl_ptr: *const sys::SSL,
33563357
vm: &VirtualMachine,
33573358
) {

crates/stdlib/src/scproxy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ mod _scproxy {
55
// straight-forward port of Modules/_scproxy.c
66

77
use crate::vm::{
8-
PyResult, VirtualMachine,
9-
builtins::{PyDictRef, PyStr},
8+
Py, PyResult, VirtualMachine,
9+
builtins::{PyDict, PyDictRef, PyStr},
1010
convert::ToPyObject,
1111
};
1212
use system_configuration::core_foundation::{
@@ -74,7 +74,7 @@ mod _scproxy {
7474

7575
let result = vm.ctx.new_dict();
7676

77-
let set_proxy = |result: &PyDictRef,
77+
let set_proxy = |result: &Py<PyDict>,
7878
proto: &str,
7979
enabled_key: CFStringRef,
8080
host_key: CFStringRef,

crates/stdlib/src/ssl/compat.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ use rustls::server::ResolvesServerCert;
2323
use rustls::server::ServerConfig;
2424
use rustls::server::ServerConnection;
2525
use rustls::sign::CertifiedKey;
26-
use rustpython_vm::builtins::PyBaseExceptionRef;
26+
use rustpython_vm::builtins::{PyBaseException, PyBaseExceptionRef};
2727
use rustpython_vm::convert::IntoPyException;
2828
use rustpython_vm::function::ArgBytesLike;
29-
use rustpython_vm::{AsObject, PyObjectRef, PyPayload, PyResult, TryFromObject};
29+
use rustpython_vm::{AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject};
3030
use std::io::Read;
3131
use std::sync::{Arc, Once};
3232

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

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

@@ -1534,7 +1534,7 @@ fn ssl_read_tls_records(
15341534

15351535
/// Check if an exception is a connection closed error
15361536
/// In SSL context, these errors indicate unexpected connection termination without proper TLS shutdown
1537-
fn is_connection_closed_error(exc: &PyBaseExceptionRef, vm: &VirtualMachine) -> bool {
1537+
fn is_connection_closed_error(exc: &Py<PyBaseException>, vm: &VirtualMachine) -> bool {
15381538
use rustpython_vm::stdlib::errno::errors;
15391539

15401540
// Check for ConnectionAbortedError, ConnectionResetError (Python exception types)

crates/vm/src/builtins/dict.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ impl ExactSizeIterator for DictIter<'_> {
753753
trait DictView: PyPayload + PyClassDef + Iterable + Representable {
754754
type ReverseIter: PyPayload + std::fmt::Debug;
755755

756-
fn dict(&self) -> &PyDictRef;
756+
fn dict(&self) -> &Py<PyDict>;
757757
fn item(vm: &VirtualMachine, key: PyObjectRef, value: PyObjectRef) -> PyObjectRef;
758758

759759
#[pymethod]
@@ -785,7 +785,7 @@ macro_rules! dict_view {
785785
impl DictView for $name {
786786
type ReverseIter = $reverse_iter_name;
787787

788-
fn dict(&self) -> &PyDictRef {
788+
fn dict(&self) -> &Py<PyDict> {
789789
&self.dict
790790
}
791791

@@ -1142,7 +1142,7 @@ impl PyDictKeys {
11421142

11431143
#[pygetset]
11441144
fn mapping(zelf: PyRef<Self>) -> PyMappingProxy {
1145-
PyMappingProxy::from(zelf.dict().clone())
1145+
PyMappingProxy::from(zelf.dict().to_owned())
11461146
}
11471147
}
11481148

@@ -1206,7 +1206,7 @@ impl PyDictItems {
12061206
}
12071207
#[pygetset]
12081208
fn mapping(zelf: PyRef<Self>) -> PyMappingProxy {
1209-
PyMappingProxy::from(zelf.dict().clone())
1209+
PyMappingProxy::from(zelf.dict().to_owned())
12101210
}
12111211
}
12121212

@@ -1269,7 +1269,7 @@ impl AsNumber for PyDictItems {
12691269
impl PyDictValues {
12701270
#[pygetset]
12711271
fn mapping(zelf: PyRef<Self>) -> PyMappingProxy {
1272-
PyMappingProxy::from(zelf.dict().clone())
1272+
PyMappingProxy::from(zelf.dict().to_owned())
12731273
}
12741274
}
12751275

crates/vm/src/builtins/function/jit.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::{
22
AsObject, Py, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine,
3-
builtins::{PyBaseExceptionRef, PyDictRef, PyFunction, PyStrInterned, bool_, float, int},
3+
builtins::{
4+
PyBaseExceptionRef, PyDict, PyDictRef, PyFunction, PyStrInterned, bool_, float, int,
5+
},
46
bytecode::CodeFlags,
57
convert::ToPyObject,
68
function::FuncArgs,
@@ -42,7 +44,7 @@ pub fn new_jit_error(msg: String, vm: &VirtualMachine) -> PyBaseExceptionRef {
4244
vm.new_exception_msg(jit_error, msg)
4345
}
4446

45-
fn get_jit_arg_type(dict: &PyDictRef, name: &str, vm: &VirtualMachine) -> PyResult<JitType> {
47+
fn get_jit_arg_type(dict: &Py<PyDict>, name: &str, vm: &VirtualMachine) -> PyResult<JitType> {
4648
if let Some(value) = dict.get_item_opt(name, vm)? {
4749
if value.is(vm.ctx.types.int_type) {
4850
Ok(JitType::Int)

crates/vm/src/builtins/genericalias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ fn is_unpacked_typevartuple(arg: &PyObject, vm: &VirtualMachine) -> PyResult<boo
312312

313313
fn subs_tvars(
314314
obj: PyObjectRef,
315-
params: &PyTupleRef,
315+
params: &Py<PyTuple>,
316316
arg_items: &[PyObjectRef],
317317
vm: &VirtualMachine,
318318
) -> PyResult {

crates/vm/src/builtins/union.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl PyUnion {
4242

4343
/// Direct access to args field, matching CPython's _Py_union_args
4444
#[inline]
45-
pub const fn args(&self) -> &PyTupleRef {
45+
pub fn args(&self) -> &Py<PyTuple> {
4646
&self.args
4747
}
4848

crates/vm/src/codecs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl PyCodec {
5252
self.0
5353
}
5454
#[inline]
55-
pub const fn as_tuple(&self) -> &PyTupleRef {
55+
pub fn as_tuple(&self) -> &Py<PyTuple> {
5656
&self.0
5757
}
5858

crates/vm/src/coroutine.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::{
2-
AsObject, PyObject, PyObjectRef, PyResult, VirtualMachine,
2+
AsObject, Py, PyObject, PyObjectRef, PyResult, VirtualMachine,
33
builtins::{PyBaseExceptionRef, PyStrRef},
44
common::lock::PyMutex,
5+
exceptions::types::PyBaseException,
56
frame::{ExecutionResult, FrameRef},
67
protocol::PyIterReturn,
78
};
@@ -207,6 +208,6 @@ impl Coro {
207208
}
208209
}
209210

210-
pub fn is_gen_exit(exc: &PyBaseExceptionRef, vm: &VirtualMachine) -> bool {
211+
pub fn is_gen_exit(exc: &Py<PyBaseException>, vm: &VirtualMachine) -> bool {
211212
exc.fast_isinstance(vm.ctx.exceptions.generator_exit)
212213
}

crates/vm/src/exception_group.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ pub(super) mod types {
357357
}
358358

359359
fn get_exceptions_tuple(
360-
exc: &PyRef<PyBaseException>,
360+
exc: &Py<PyBaseException>,
361361
vm: &VirtualMachine,
362362
) -> PyResult<Vec<PyObjectRef>> {
363363
let obj = exc
@@ -429,7 +429,7 @@ pub(super) mod types {
429429
}
430430

431431
fn derive_and_copy_attributes(
432-
orig: &PyRef<PyBaseException>,
432+
orig: &Py<PyBaseException>,
433433
excs: Vec<PyObjectRef>,
434434
vm: &VirtualMachine,
435435
) -> PyResult<PyObjectRef> {

0 commit comments

Comments
 (0)