Skip to content

Commit b9f741a

Browse files
committed
Rename PyAny -> PyObject
1 parent 643df0b commit b9f741a

Some content is hidden

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

66 files changed

+538
-538
lines changed

examples/rustapi_module/src/objstore.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use pyo3::prelude::*;
33
#[pyclass]
44
#[derive(Default)]
55
pub struct ObjStore {
6-
obj: Vec<Py<PyAny>>,
6+
obj: Vec<Py<PyObject>>,
77
}
88

99
#[pymethods]
@@ -13,7 +13,7 @@ impl ObjStore {
1313
ObjStore::default()
1414
}
1515

16-
fn push(&mut self, py: Python, obj: &PyAny) {
16+
fn push(&mut self, py: Python, obj: &PyObject) {
1717
self.obj.push(obj.to_object(py).into());
1818
}
1919
}

guide/src/class.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ impl pyo3::pyclass::PyClassAlloc for MyClass {}
3232

3333
unsafe impl pyo3::PyTypeInfo for MyClass {
3434
type Type = MyClass;
35-
type BaseType = PyAny;
36-
type BaseLayout = pyo3::pycell::PyCellBase<PyAny>;
35+
type BaseType = PyObject;
36+
type BaseLayout = pyo3::pycell::PyCellBase<PyObject>;
3737
type Layout = PyCell<Self>;
3838
type Initializer = PyClassInitializer<Self>;
3939
type AsRefTarget = PyCell<Self>;
@@ -54,7 +54,7 @@ unsafe impl pyo3::PyTypeInfo for MyClass {
5454
impl pyo3::pyclass::PyClass for MyClass {
5555
type Dict = pyo3::pyclass_slots::PyClassDummySlot;
5656
type WeakRef = pyo3::pyclass_slots::PyClassDummySlot;
57-
type BaseNativeType = PyAny;
57+
type BaseNativeType = PyObject;
5858
}
5959

6060
impl pyo3::IntoPy<PyObject> for MyClass {
@@ -240,7 +240,7 @@ Consult the table below to determine which type your constructor should return:
240240

241241
## Inheritance
242242

243-
By default, `PyAny` is used as the base class. To override this default,
243+
By default, `PyObject` is used as the base class. To override this default,
244244
use the `extends` parameter for `pyclass` with the full path to the base class.
245245

246246
For convenience, `(T, U)` implements `Into<PyClassInitializer<T>>` where `U` is the
@@ -340,7 +340,7 @@ impl DictWithCounter {
340340
fn new() -> Self {
341341
Self::default()
342342
}
343-
fn set(mut self_: PyRefMut<Self>, key: String, value: &PyAny) -> PyResult<()> {
343+
fn set(mut self_: PyRefMut<Self>, key: String, value: &PyObject) -> PyResult<()> {
344344
self_.counter.entry(key.clone()).or_insert(0);
345345
let py = self_.py();
346346
let dict: &PyDict = unsafe { py.from_borrowed_ptr_or_err(self_.as_ptr())? };

guide/src/python_from_rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PyO3 is built for an extension module or not.
77

88
[`Python::eval`](https://pyo3.rs/master/doc/pyo3/struct.Python.html#method.eval) is
99
a method to execute a [Python expression](https://docs.python.org/3.7/reference/expressions.html)
10-
and return the evaluated value as a `&PyAny` object.
10+
and return the evaluated value as a `&PyObject` object.
1111

1212
```rust
1313
use pyo3::prelude::*;

guide/src/rust_cpython.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl PyList {
6969
7070
fn new(py: Python) -> &PyList {...}
7171
72-
fn get_item(&self, index: isize) -> &PyAny {...}
72+
fn get_item(&self, index: isize) -> &PyObject {...}
7373
}
7474
```
7575

guide/src/types.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ In PyO3, holding the GIL is modeled by acquiring a token of the type
2626
* It can be passed to functions that require a proof of holding the GIL,
2727
such as [`PyObject::clone_ref`][clone_ref].
2828
* Its lifetime can be used to create Rust references that implicitly guarantee
29-
holding the GIL, such as [`&'py PyAny`][PyAny].
29+
holding the GIL, such as [`&'py PyObject`][PyObject].
3030

3131
The latter two points are the reason why some APIs in PyO3 require the `py:
3232
Python` argument, while others don't.
@@ -60,7 +60,7 @@ Can be cloned using Python reference counts with `.clone_ref()`.
6060

6161
**Conversions:**
6262

63-
- To `&PyAny`: `obj.as_ref(py)`
63+
- To `&PyObject`: `obj.as_ref(py)`
6464
- To `Py<ConcreteType>`: `obj.as_ref(py).extract::<Py<ConcreteType>>`
6565
- To `&ConcreteType` (which must be a Python native type): `obj.cast_as(py)`
6666

@@ -80,15 +80,15 @@ implemented in Rust.
8080
implemented in Rust, you get a `PyCell` (see below). For Python native types,
8181
mutating operations through PyO3's API don't require `&mut` access.
8282

83-
**Note:** `PyObject` is semantically equivalent to `Py<PyAny>` and might be
83+
**Note:** `PyObject` is semantically equivalent to `Py<PyObject>` and might be
8484
merged with it in the future.
8585

8686

87-
### `PyAny`
87+
### `PyObject`
8888

8989
**Represents:** a Python object of unspecified type, restricted to a GIL
90-
lifetime. Currently, `PyAny` can only ever occur as a reference, usually
91-
`&PyAny`.
90+
lifetime. Currently, `PyObject` can only ever occur as a reference, usually
91+
`&PyObject`.
9292

9393
**Used:** Whenever you want to refer to some Python object only as long as
9494
holding the GIL. For example, intermediate values and arguments to
@@ -102,15 +102,15 @@ holding the GIL. For example, intermediate values and arguments to
102102
### `PyTuple`, `PyDict`, and many more
103103

104104
**Represents:** a native Python object of known type, restricted to a GIL
105-
lifetime just like `PyAny`.
105+
lifetime just like `PyObject`.
106106

107107
**Used:** Whenever you want to operate with native Python types while holding
108-
the GIL. Like `PyAny`, this is the most convenient form to use for function
108+
the GIL. Like `PyObject`, this is the most convenient form to use for function
109109
arguments and intermediate values.
110110

111111
**Conversions:**
112112

113-
- To `PyAny`: `obj.as_ref()`
113+
- To `PyObject`: `obj.as_ref()`
114114
- To `Py<T>`: `Py::from(obj)`
115115

116116

@@ -126,7 +126,7 @@ Rust references.
126126

127127
**Conversions:**
128128

129-
- From `PyAny`: `.downcast()`
129+
- From `PyObject`: `.downcast()`
130130

131131

132132
### `PyRef<SomeType>` and `PyRefMut<SomeType>`
@@ -135,7 +135,7 @@ Rust references.
135135
borrows, analog to `Ref` and `RefMut` used by `RefCell`.
136136

137137
**Used:** while borrowing a `PyCell`. They can also be used with `.extract()`
138-
on types like `Py<T>` and `PyAny` to get a reference quickly.
138+
on types like `Py<T>` and `PyObject` to get a reference quickly.
139139

140140

141141

@@ -154,6 +154,6 @@ This trait marks structs that mirror native Python types, such as `PyList`.
154154

155155
[eval]: https://docs.rs/pyo3/latest/pyo3/struct.Python.html#method.eval
156156
[clone_ref]: https://docs.rs/pyo3/latest/pyo3/struct.PyObject.html#method.clone_ref
157-
[PyAny]: https://docs.rs/pyo3/latest/pyo3/types/struct.PyAny.html
157+
[PyObject]: https://docs.rs/pyo3/latest/pyo3/types/struct.PyObject.html
158158
[PyList_append]: https://docs.rs/pyo3/latest/pyo3/types/struct.PyList.html#method.append
159159
[RefCell]: https://doc.rust-lang.org/std/cell/struct.RefCell.html

pyo3-derive-backend/src/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub fn add_fn_to_module(
178178
let wrapper = function_c_wrapper(&func.sig.ident, &spec);
179179

180180
Ok(quote! {
181-
fn #function_wrapper_ident(py: pyo3::Python) -> pyo3::Py<pyo3::PyAny> {
181+
fn #function_wrapper_ident(py: pyo3::Python) -> pyo3::Py<pyo3::PyObject> {
182182
#wrapper
183183

184184
let _def = pyo3::class::PyMethodDef {

pyo3-derive-backend/src/pyclass.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Default for PyClassArgs {
4343
// We need the 0 as value for the constant we're later building using quote for when there
4444
// are no other flags
4545
flags: vec![parse_quote! { 0 }],
46-
base: parse_quote! { pyo3::PyAny },
46+
base: parse_quote! { pyo3::PyObject },
4747
has_extends: false,
4848
}
4949
}
@@ -357,19 +357,19 @@ fn impl_class(
357357
let base_layout = if attr.has_extends {
358358
quote! { <Self::BaseType as pyo3::derive_utils::PyBaseTypeUtils>::LayoutAsBase }
359359
} else {
360-
quote! { pyo3::pycell::PyCellBase<pyo3::PyAny> }
360+
quote! { pyo3::pycell::PyCellBase<pyo3::PyObject> }
361361
};
362362
let base_nativetype = if attr.has_extends {
363363
quote! { <Self::BaseType as pyo3::derive_utils::PyBaseTypeUtils>::BaseNativeType }
364364
} else {
365-
quote! { pyo3::PyAny }
365+
quote! { pyo3::PyObject }
366366
};
367367

368-
// If #cls is not extended type, we allow Self->Py<PyAny> conversion
368+
// If #cls is not extended type, we allow Self->Py<PyObject> conversion
369369
let into_pyobject = if !attr.has_extends {
370370
quote! {
371-
impl pyo3::IntoPy<Py<PyAny>> for #cls {
372-
fn into_py(self, py: pyo3::Python) -> pyo3::Py<PyAny> {
371+
impl pyo3::IntoPy<Py<PyObject>> for #cls {
372+
fn into_py(self, py: pyo3::Python) -> pyo3::Py<PyObject> {
373373
pyo3::IntoPy::into_py(pyo3::Py::new(py, self).unwrap(), py)
374374
}
375375
}

pyo3-derive-backend/src/pymethod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ pub(crate) fn impl_wrap_setter(
377377
let _pool = pyo3::GILPool::new(_py);
378378
let _slf = _py.from_borrowed_ptr::<pyo3::PyCell<#cls>>(_slf);
379379
#borrow_self
380-
let _value = _py.from_borrowed_ptr::<pyo3::types::PyAny>(_value);
380+
let _value = _py.from_borrowed_ptr::<pyo3::types::PyObject>(_value);
381381
let _val = pyo3::FromPyObject::extract(_value)?;
382382
pyo3::callback::convert(_py, {#setter_impl})
383383
})

src/buffer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
//! `PyBuffer` implementation
2020
use crate::err::{self, PyResult};
21-
use crate::{exceptions, ffi, AsPyPointer, PyAny, Python};
21+
use crate::{exceptions, ffi, AsPyPointer, PyObject, Python};
2222
use std::ffi::CStr;
2323
use std::os::raw;
2424
use std::pin::Pin;
@@ -160,7 +160,7 @@ fn validate(b: &ffi::Py_buffer) {
160160

161161
impl PyBuffer {
162162
/// Get the underlying buffer from the specified python object.
163-
pub fn get(py: Python, obj: &PyAny) -> PyResult<PyBuffer> {
163+
pub fn get(py: Python, obj: &PyObject) -> PyResult<PyBuffer> {
164164
unsafe {
165165
let mut buf = Box::pin(mem::zeroed::<ffi::Py_buffer>());
166166
err::error_on_minusone(

src/callback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::err::PyResult;
66
use crate::exceptions::OverflowError;
77
use crate::ffi::{self, Py_hash_t};
88
use crate::IntoPyPointer;
9-
use crate::{IntoPy, PyAny, Py, Python};
9+
use crate::{IntoPy, PyObject, Py, Python};
1010
use std::isize;
1111
use std::os::raw::c_int;
1212

@@ -48,7 +48,7 @@ where
4848

4949
impl<T> IntoPyCallbackOutput<*mut ffi::PyObject> for T
5050
where
51-
T: IntoPy<Py<PyAny>>,
51+
T: IntoPy<Py<PyObject>>,
5252
{
5353
fn convert(self, py: Python) -> PyResult<*mut ffi::PyObject> {
5454
Ok(self.into_py(py).into_ptr())

src/class/basic.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use crate::callback::HashCallbackOutput;
1212
use crate::class::methods::PyMethodDef;
1313
use crate::{
14-
callback, exceptions, ffi, run_callback, FromPyObject, GILPool, IntoPy, ObjectProtocol, PyAny,
14+
callback, exceptions, ffi, run_callback, FromPyObject, GILPool, IntoPy, ObjectProtocol, PyObject,
1515
PyCell, PyClass, PyErr, Py, PyResult, Python,
1616
};
1717
use std::os::raw::c_int;
@@ -103,7 +103,7 @@ pub trait PyObjectProtocol<'p>: PyClass {
103103

104104
pub trait PyObjectGetAttrProtocol<'p>: PyObjectProtocol<'p> {
105105
type Name: FromPyObject<'p>;
106-
type Success: IntoPy<Py<PyAny>>;
106+
type Success: IntoPy<Py<PyObject>>;
107107
type Result: Into<PyResult<Self::Success>>;
108108
}
109109
pub trait PyObjectSetAttrProtocol<'p>: PyObjectProtocol<'p> {
@@ -116,16 +116,16 @@ pub trait PyObjectDelAttrProtocol<'p>: PyObjectProtocol<'p> {
116116
type Result: Into<PyResult<()>>;
117117
}
118118
pub trait PyObjectStrProtocol<'p>: PyObjectProtocol<'p> {
119-
type Success: IntoPy<Py<PyAny>>;
119+
type Success: IntoPy<Py<PyObject>>;
120120
type Result: Into<PyResult<Self::Success>>;
121121
}
122122
pub trait PyObjectReprProtocol<'p>: PyObjectProtocol<'p> {
123-
type Success: IntoPy<Py<PyAny>>;
123+
type Success: IntoPy<Py<PyObject>>;
124124
type Result: Into<PyResult<Self::Success>>;
125125
}
126126
pub trait PyObjectFormatProtocol<'p>: PyObjectProtocol<'p> {
127127
type Format: FromPyObject<'p>;
128-
type Success: IntoPy<Py<PyAny>>;
128+
type Success: IntoPy<Py<PyObject>>;
129129
type Result: Into<PyResult<Self::Success>>;
130130
}
131131
pub trait PyObjectHashProtocol<'p>: PyObjectProtocol<'p> {
@@ -135,12 +135,12 @@ pub trait PyObjectBoolProtocol<'p>: PyObjectProtocol<'p> {
135135
type Result: Into<PyResult<bool>>;
136136
}
137137
pub trait PyObjectBytesProtocol<'p>: PyObjectProtocol<'p> {
138-
type Success: IntoPy<Py<PyAny>>;
138+
type Success: IntoPy<Py<PyObject>>;
139139
type Result: Into<PyResult<Self::Success>>;
140140
}
141141
pub trait PyObjectRichcmpProtocol<'p>: PyObjectProtocol<'p> {
142142
type Other: FromPyObject<'p>;
143-
type Success: IntoPy<Py<PyAny>>;
143+
type Success: IntoPy<Py<PyObject>>;
144144
type Result: Into<PyResult<Self::Success>>;
145145
}
146146

@@ -233,7 +233,7 @@ where
233233
}
234234

235235
let slf = py.from_borrowed_ptr::<PyCell<T>>(slf);
236-
let arg = py.from_borrowed_ptr::<PyAny>(arg);
236+
let arg = py.from_borrowed_ptr::<PyObject>(arg);
237237
callback::convert(py, call_ref!(slf, __getattr__, arg))
238238
})
239239
}
@@ -489,7 +489,7 @@ where
489489
run_callback(py, || {
490490
let _pool = GILPool::new(py);
491491
let slf = py.from_borrowed_ptr::<crate::PyCell<T>>(slf);
492-
let arg = py.from_borrowed_ptr::<PyAny>(arg);
492+
let arg = py.from_borrowed_ptr::<PyObject>(arg);
493493

494494
let borrowed_slf = slf.try_borrow()?;
495495
let op = extract_op(op)?;

src/class/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use crate::class::methods::PyMethodDef;
88
use crate::err::PyResult;
9-
use crate::{PyClass, Py, PyAny};
9+
use crate::{PyClass, Py, PyObject};
1010

1111
/// Context manager interface
1212
#[allow(unused_variables)]
@@ -32,15 +32,15 @@ pub trait PyContextProtocol<'p>: PyClass {
3232
}
3333

3434
pub trait PyContextEnterProtocol<'p>: PyContextProtocol<'p> {
35-
type Success: crate::IntoPy<Py<PyAny>>;
35+
type Success: crate::IntoPy<Py<PyObject>>;
3636
type Result: Into<PyResult<Self::Success>>;
3737
}
3838

3939
pub trait PyContextExitProtocol<'p>: PyContextProtocol<'p> {
4040
type ExcType: crate::FromPyObject<'p>;
4141
type ExcValue: crate::FromPyObject<'p>;
4242
type Traceback: crate::FromPyObject<'p>;
43-
type Success: crate::IntoPy<Py<PyAny>>;
43+
type Success: crate::IntoPy<Py<PyObject>>;
4444
type Result: Into<PyResult<Self::Success>>;
4545
}
4646

src/class/descr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@
77
88
use crate::class::methods::PyMethodDef;
99
use crate::err::PyResult;
10-
use crate::types::{PyAny, PyType};
10+
use crate::types::{PyObject, PyType};
1111
use crate::{ffi, FromPyObject, IntoPy, PyClass, Py};
1212
use std::os::raw::c_int;
1313

1414
/// Descriptor interface
1515
#[allow(unused_variables)]
1616
pub trait PyDescrProtocol<'p>: PyClass {
17-
fn __get__(&'p self, instance: &'p PyAny, owner: Option<&'p PyType>) -> Self::Result
17+
fn __get__(&'p self, instance: &'p PyObject, owner: Option<&'p PyType>) -> Self::Result
1818
where
1919
Self: PyDescrGetProtocol<'p>,
2020
{
2121
unimplemented!()
2222
}
2323

24-
fn __set__(&'p self, instance: &'p PyAny, value: &'p PyAny) -> Self::Result
24+
fn __set__(&'p self, instance: &'p PyObject, value: &'p PyObject) -> Self::Result
2525
where
2626
Self: PyDescrSetProtocol<'p>,
2727
{
2828
unimplemented!()
2929
}
3030

31-
fn __delete__(&'p self, instance: &'p PyAny) -> Self::Result
31+
fn __delete__(&'p self, instance: &'p PyObject) -> Self::Result
3232
where
3333
Self: PyDescrDeleteProtocol<'p>,
3434
{
3535
unimplemented!()
3636
}
3737

38-
fn __set_name__(&'p self, instance: &'p PyAny) -> Self::Result
38+
fn __set_name__(&'p self, instance: &'p PyObject) -> Self::Result
3939
where
4040
Self: PyDescrSetNameProtocol<'p>,
4141
{
@@ -46,7 +46,7 @@ pub trait PyDescrProtocol<'p>: PyClass {
4646
pub trait PyDescrGetProtocol<'p>: PyDescrProtocol<'p> {
4747
type Inst: FromPyObject<'p>;
4848
type Owner: FromPyObject<'p>;
49-
type Success: IntoPy<Py<PyAny>>;
49+
type Success: IntoPy<Py<PyObject>>;
5050
type Result: Into<PyResult<Self::Success>>;
5151
}
5252

0 commit comments

Comments
 (0)