Skip to content

Commit c103fe1

Browse files
authored
Merge pull request #3630 from youknowone/rename-pyobjectview
Rename PyObjectView -> Py and PyValue -> PyPayload
2 parents 400402a + 5a60664 commit c103fe1

102 files changed

Lines changed: 553 additions & 604 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎common/src/rc.rs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(not(feature = "threading"))]
2-
use std::rc::{Rc, Weak};
2+
use std::rc::Rc;
33
#[cfg(feature = "threading")]
4-
use std::sync::{Arc, Weak};
4+
use std::sync::Arc;
55

66
// type aliases instead of newtypes because you can't do `fn method(self: PyRc<Self>)` with a
77
// newtype; requires the arbitrary_self_types unstable feature
@@ -10,5 +10,3 @@ use std::sync::{Arc, Weak};
1010
pub type PyRc<T> = Arc<T>;
1111
#[cfg(not(feature = "threading"))]
1212
pub type PyRc<T> = Rc<T>;
13-
14-
pub type PyWeak<T> = Weak<T>;

‎derive/src/lib.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ mod doc;
1717
mod from_args;
1818
mod pyclass;
1919
mod pymodule;
20+
mod pypayload;
2021
mod pystructseq;
21-
mod pyvalue;
2222

2323
use error::{extract_spans, Diagnostic};
2424
use proc_macro2::TokenStream;
@@ -120,8 +120,8 @@ pub fn py_freeze(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
120120
result_to_tokens(compile_bytecode::impl_py_freeze(input.into()))
121121
}
122122

123-
#[proc_macro_derive(PyValue)]
124-
pub fn pyvalue(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
123+
#[proc_macro_derive(PyPayload)]
124+
pub fn pypayload(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
125125
let input = parse_macro_input!(input as DeriveInput);
126-
result_to_tokens(pyvalue::impl_pyvalue(input))
126+
result_to_tokens(pypayload::impl_pypayload(input))
127127
}

‎derive/src/pyclass.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ pub(crate) fn impl_define_exception(exc_def: PyExceptionDef) -> Result<TokenStre
364364
pub struct #class_name {}
365365

366366
// We need this to make extend mechanism work:
367-
impl ::rustpython_vm::PyValue for #class_name {
367+
impl ::rustpython_vm::PyPayload for #class_name {
368368
fn class(vm: &::rustpython_vm::VirtualMachine) -> &::rustpython_vm::builtins::PyTypeRef {
369369
&vm.ctx.exceptions.#ctx_name
370370
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use proc_macro2::TokenStream;
22
use quote::quote;
33
use syn::{DeriveInput, Result};
44

5-
pub(crate) fn impl_pyvalue(input: DeriveInput) -> Result<TokenStream> {
5+
pub(crate) fn impl_pypayload(input: DeriveInput) -> Result<TokenStream> {
66
let ty = &input.ident;
77

88
let ret = quote! {
9-
impl ::rustpython_vm::PyValue for #ty {
9+
impl ::rustpython_vm::PyPayload for #ty {
1010
fn class(_vm: &::rustpython_vm::VirtualMachine) -> &rustpython_vm::builtins::PyTypeRef {
1111
<Self as ::rustpython_vm::pyclass::StaticType>::static_type()
1212
}

‎stdlib/src/array.rs‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ mod array {
3131
AsBuffer, AsMapping, Comparable, Constructor, IterNext, IterNextIterable, Iterable,
3232
PyComparisonOp,
3333
},
34-
AsObject, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue,
35-
VirtualMachine,
34+
AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
3635
},
3736
};
3837
use itertools::Itertools;
@@ -583,7 +582,7 @@ mod array {
583582

584583
#[pyattr]
585584
#[pyclass(name = "array")]
586-
#[derive(Debug, PyValue)]
585+
#[derive(Debug, PyPayload)]
587586
pub struct PyArray {
588587
array: PyRwLock<ArrayContentType>,
589588
exports: AtomicUsize,
@@ -1152,7 +1151,7 @@ mod array {
11521151

11531152
impl Comparable for PyArray {
11541153
fn cmp(
1155-
zelf: &PyObjectView<Self>,
1154+
zelf: &Py<Self>,
11561155
other: &PyObject,
11571156
op: PyComparisonOp,
11581157
vm: &VirtualMachine,
@@ -1203,7 +1202,7 @@ mod array {
12031202
}
12041203

12051204
impl AsBuffer for PyArray {
1206-
fn as_buffer(zelf: &PyObjectView<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
1205+
fn as_buffer(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
12071206
let array = zelf.read();
12081207
let buf = PyBuffer::new(
12091208
zelf.to_owned().into(),
@@ -1254,7 +1253,7 @@ mod array {
12541253
}
12551254

12561255
impl AsMapping for PyArray {
1257-
fn as_mapping(_zelf: &PyObjectView<Self>, _vm: &VirtualMachine) -> PyMappingMethods {
1256+
fn as_mapping(_zelf: &Py<Self>, _vm: &VirtualMachine) -> PyMappingMethods {
12581257
Self::MAPPING_METHODS
12591258
}
12601259
}
@@ -1280,7 +1279,7 @@ mod array {
12801279

12811280
#[pyattr]
12821281
#[pyclass(name = "array_iterator")]
1283-
#[derive(Debug, PyValue)]
1282+
#[derive(Debug, PyPayload)]
12841283
pub struct PyArrayIter {
12851284
position: AtomicUsize,
12861285
array: PyArrayRef,
@@ -1291,7 +1290,7 @@ mod array {
12911290

12921291
impl IterNextIterable for PyArrayIter {}
12931292
impl IterNext for PyArrayIter {
1294-
fn next(zelf: &PyObjectView<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
1293+
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
12951294
let pos = zelf.position.fetch_add(1, atomic::Ordering::SeqCst);
12961295
let r = if let Some(item) = zelf.array.read().get(pos, vm) {
12971296
PyIterReturn::Return(item?)

‎stdlib/src/contextvars.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ pub(crate) use _contextvars::make_module;
44
mod _contextvars {
55
use rustpython_vm::builtins::{PyFunction, PyStrRef, PyTypeRef};
66
use rustpython_vm::function::{ArgCallable, FuncArgs, OptionalArg};
7-
use rustpython_vm::{PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine};
7+
use rustpython_vm::{PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine};
88

99
#[pyattr]
1010
#[pyclass(name)]
11-
#[derive(Debug, PyValue)]
11+
#[derive(Debug, PyPayload)]
1212
struct Context {}
1313

1414
#[pyimpl]
@@ -75,7 +75,7 @@ mod _contextvars {
7575

7676
#[pyattr]
7777
#[pyclass(name)]
78-
#[derive(Debug, PyValue)]
78+
#[derive(Debug, PyPayload)]
7979
struct ContextVar {
8080
#[allow(dead_code)] // TODO: RUSTPYTHON
8181
name: String,
@@ -147,7 +147,7 @@ mod _contextvars {
147147

148148
#[pyattr]
149149
#[pyclass(name = "Token")]
150-
#[derive(Debug, PyValue)]
150+
#[derive(Debug, PyPayload)]
151151
struct ContextToken {}
152152

153153
#[derive(FromArgs)]

‎stdlib/src/csv.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod _csv {
99
match_class,
1010
protocol::{PyIter, PyIterReturn},
1111
types::{IterNext, IterNextIterable},
12-
AsObject, PyObjectRef, PyObjectView, PyResult, PyValue, TryFromObject, VirtualMachine,
12+
AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine,
1313
};
1414
use itertools::{self, Itertools};
1515
use std::fmt;
@@ -153,7 +153,7 @@ mod _csv {
153153
}
154154

155155
#[pyclass(noattr, module = "_csv", name = "reader")]
156-
#[derive(PyValue)]
156+
#[derive(PyPayload)]
157157
pub(super) struct Reader {
158158
iter: PyIter,
159159
state: PyMutex<ReadState>,
@@ -169,7 +169,7 @@ mod _csv {
169169
impl Reader {}
170170
impl IterNextIterable for Reader {}
171171
impl IterNext for Reader {
172-
fn next(zelf: &PyObjectView<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
172+
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
173173
let string = match zelf.iter.next(vm)? {
174174
PyIterReturn::Return(obj) => obj,
175175
PyIterReturn::StopIteration(v) => return Ok(PyIterReturn::StopIteration(v)),
@@ -243,7 +243,7 @@ mod _csv {
243243
}
244244

245245
#[pyclass(noattr, module = "_csv", name = "writer")]
246-
#[derive(PyValue)]
246+
#[derive(PyPayload)]
247247
pub(super) struct Writer {
248248
write: PyObjectRef,
249249
state: PyMutex<WriteState>,

‎stdlib/src/hashlib.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod hashlib {
66
use crate::vm::{
77
builtins::{PyBytes, PyBytesRef, PyStrRef, PyTypeRef},
88
function::{FuncArgs, OptionalArg},
9-
PyResult, PyValue, VirtualMachine,
9+
PyPayload, PyResult, VirtualMachine,
1010
};
1111
use blake2::{Blake2b512, Blake2s256};
1212
use digest::DynDigest;
@@ -46,7 +46,7 @@ mod hashlib {
4646

4747
#[pyattr]
4848
#[pyclass(module = "hashlib", name = "hasher")]
49-
#[derive(PyValue)]
49+
#[derive(PyPayload)]
5050
struct PyHasher {
5151
name: String,
5252
buffer: PyRwLock<HashWrapper>,

‎stdlib/src/json.rs‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ mod _json {
1010
function::OptionalArg,
1111
protocol::PyIterReturn,
1212
types::{Callable, Constructor},
13-
AsObject, PyObjectRef, PyObjectView, PyResult, PyValue, VirtualMachine,
13+
AsObject, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
1414
};
1515
use num_bigint::BigInt;
1616
use std::str::FromStr;
1717

1818
#[pyattr(name = "make_scanner")]
1919
#[pyclass(name = "Scanner")]
20-
#[derive(Debug, PyValue)]
20+
#[derive(Debug, PyPayload)]
2121
struct JsonScanner {
2222
strict: bool,
2323
object_hook: Option<PyObjectRef>,
@@ -196,11 +196,7 @@ mod _json {
196196

197197
impl Callable for JsonScanner {
198198
type Args = (PyStrRef, isize);
199-
fn call(
200-
zelf: &PyObjectView<Self>,
201-
(pystr, idx): Self::Args,
202-
vm: &VirtualMachine,
203-
) -> PyResult {
199+
fn call(zelf: &Py<Self>, (pystr, idx): Self::Args, vm: &VirtualMachine) -> PyResult {
204200
if idx < 0 {
205201
return Err(vm.new_value_error("idx cannot be negative".to_owned()));
206202
}

‎stdlib/src/pyexpat.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ mod _pyexpat {
3535
builtins::{PyStr, PyStrRef, PyTypeRef},
3636
function::ArgBytesLike,
3737
function::{IntoFuncArgs, OptionalArg},
38-
PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine,
38+
PyContext, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine,
3939
};
4040
use rustpython_common::lock::PyRwLock;
4141
use std::io::Cursor;
@@ -44,7 +44,7 @@ mod _pyexpat {
4444

4545
#[pyattr]
4646
#[pyclass(name = "xmlparser", module = false)]
47-
#[derive(Debug, PyValue)]
47+
#[derive(Debug, PyPayload)]
4848
pub struct PyExpatLikeXmlParser {
4949
start_element: MutableObject,
5050
end_element: MutableObject,

0 commit comments

Comments
 (0)