Skip to content

Commit b796776

Browse files
committed
Rename PyAny -> PyObject
1 parent 1189310 commit b796776

Some content is hidden

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

70 files changed

+575
-569
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: 16 additions & 16 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,11 +54,11 @@ 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

60-
impl pyo3::IntoPy<pyo3::Py<pyo3::PyAny>> for MyClass {
61-
fn into_py(self, py: pyo3::Python) -> pyo3::Py<pyo3::PyAny> {
60+
impl pyo3::IntoPy<pyo3::Py<pyo3::PyObject>> for MyClass {
61+
fn into_py(self, py: pyo3::Python) -> pyo3::Py<pyo3::PyObject> {
6262
pyo3::IntoPy::into_py(pyo3::Py::new(py, self).unwrap(), py)
6363
}
6464
}
@@ -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())? };
@@ -498,7 +498,7 @@ impl MyClass {
498498
```
499499

500500
Calls to these methods are protected by the GIL, so both `&self` and `&mut self` can be used.
501-
The return type must be `PyResult<T>` or `T` for some `T` that implements `IntoPy<Py<PyAny>>`;
501+
The return type must be `PyResult<T>` or `T` for some `T` that implements `IntoPy<Py<PyObject>>`;
502502
the latter is allowed if the method cannot raise Python exceptions.
503503

504504
A `Python` parameter can be specified as part of method signature, in this case the `py` argument
@@ -549,13 +549,13 @@ Declares a class method callable from Python.
549549
This may be the type object of a derived class.
550550
* The first parameter implicitly has type `&PyType`.
551551
* For details on `parameter-list`, see the documentation of `Method arguments` section.
552-
* The return type must be `PyResult<T>` or `T` for some `T` that implements `IntoPy<Py<PyAny>>`.
552+
* The return type must be `PyResult<T>` or `T` for some `T` that implements `IntoPy<Py<PyObject>>`.
553553

554554
## Static methods
555555

556556
To create a static method for a custom class, the method needs to be annotated with the
557557
`#[staticmethod]` attribute. The return type must be `T` or `PyResult<T>` for some `T` that implements
558-
`IntoPy<Py<PyAny>>`.
558+
`IntoPy<Py<PyObject>>`.
559559

560560
```rust
561561
# use pyo3::prelude::*;
@@ -699,7 +699,7 @@ The [`PyObjectProtocol`] trait provides several basic customizations.
699699

700700
To customize object attribute access, define the following methods:
701701

702-
* `fn __getattr__(&self, name: FromPyObject) -> PyResult<impl IntoPy<Py<PyAny>>>`
702+
* `fn __getattr__(&self, name: FromPyObject) -> PyResult<impl IntoPy<Py<PyObject>>>`
703703
* `fn __setattr__(&mut self, name: FromPyObject, value: FromPyObject) -> PyResult<()>`
704704
* `fn __delattr__(&mut self, name: FromPyObject) -> PyResult<()>`
705705

@@ -764,7 +764,7 @@ use pyo3::gc::{PyGCProtocol, PyVisit};
764764

765765
#[pyclass]
766766
struct ClassWithGCSupport {
767-
obj: Option<Py<PyAny>>,
767+
obj: Option<Py<PyObject>>,
768768
}
769769

770770
#[pyproto]
@@ -805,8 +805,8 @@ struct GCTracked {} // Fails because it does not implement PyGCProtocol
805805
Iterators can be defined using the
806806
[`PyIterProtocol`](https://docs.rs/pyo3/latest/pyo3/class/iter/trait.PyIterProtocol.html) trait.
807807
It includes two methods `__iter__` and `__next__`:
808-
* `fn __iter__(slf: PyRefMut<Self>) -> PyResult<impl IntoPy<Py<PyAny>>>`
809-
* `fn __next__(slf: PyRefMut<Self>) -> PyResult<Option<impl IntoPy<Py<PyAny>>>>`
808+
* `fn __iter__(slf: PyRefMut<Self>) -> PyResult<impl IntoPy<Py<PyObject>>>`
809+
* `fn __next__(slf: PyRefMut<Self>) -> PyResult<Option<impl IntoPy<Py<PyObject>>>>`
810810

811811
Returning `Ok(None)` from `__next__` indicates that that there are no further items.
812812
These two methods can be take either `PyRef<Self>` or `PyRefMut<Self>` as their
@@ -821,15 +821,15 @@ use pyo3::PyIterProtocol;
821821

822822
#[pyclass]
823823
struct MyIterator {
824-
iter: Box<Iterator<Item = Py<PyAny>> + Send>,
824+
iter: Box<Iterator<Item = Py<PyObject>> + Send>,
825825
}
826826

827827
#[pyproto]
828828
impl PyIterProtocol for MyIterator {
829829
fn __iter__(slf: PyRef<Self>) -> PyResult<Py<MyIterator>> {
830830
Ok(slf.into())
831831
}
832-
fn __next__(mut slf: PyRefMut<Self>) -> PyResult<Option<Py<PyAny>>> {
832+
fn __next__(mut slf: PyRefMut<Self>) -> PyResult<Option<Py<PyObject>>> {
833833
Ok(slf.iter.next())
834834
}
835835
}

guide/src/conversions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ and [`PyRefMut`]. They work like the reference wrappers of
2727
## The `ToPyObject` trait
2828

2929
[`ToPyObject`] is a conversion trait that allows various objects to be
30-
converted into [`&PyAny`]. `IntoPy<Py<PyAny>>` serves the
30+
converted into [`&PyObject`]. `IntoPy<Py<PyObject>>` serves the
3131
same purpose, except that it consumes `self`.
3232

3333

@@ -48,7 +48,7 @@ use pyo3::types::{PyDict, PyTuple};
4848

4949
struct SomeObject;
5050
impl SomeObject {
51-
fn new(py: Python) -> &PyAny {
51+
fn new(py: Python) -> &PyObject {
5252
PyDict::new(py).to_object(py)
5353
}
5454
}
@@ -89,7 +89,7 @@ use std::collections::HashMap;
8989
struct SomeObject;
9090

9191
impl SomeObject {
92-
fn new(py: Python) -> &PyAny {
92+
fn new(py: Python) -> &PyObject {
9393
PyDict::new(py).to_object(py)
9494
}
9595
}
@@ -135,7 +135,7 @@ Eventually, traits such as [`ToPyObject`] will be replaced by this trait and a [
135135
[`FromPy`]: https://docs.rs/pyo3/latest/pyo3/trait.FromPy.html
136136
[`FromPyObject`]: https://docs.rs/pyo3/latest/pyo3/types/trait.FromPyObject.html
137137
[`ToPyObject`]: https://docs.rs/pyo3/latest/pyo3/trait.ToPyObject.html
138-
[`PyAny`]: https://docs.rs/pyo3/latest/pyo3/struct.PyAny.html
138+
[`PyObject`]: https://docs.rs/pyo3/latest/pyo3/struct.PyObject.html
139139
[`PyTuple`]: https://docs.rs/pyo3/latest/pyo3/types/struct.PyTuple.html
140140
[`ObjectProtocol`]: https://docs.rs/pyo3/latest/pyo3/trait.ObjectProtocol.html
141141
[`IntoPyDict`]: https://docs.rs/pyo3/latest/pyo3/types/trait.IntoPyDict.html

guide/src/exception.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ have Rust types as well.
6868
# use pyo3::exceptions;
6969
# use pyo3::prelude::*;
7070
# fn check_for_error() -> bool {false}
71-
fn my_func(arg: &PyAny) -> PyResult<()> {
71+
fn my_func(arg: &PyObject) -> PyResult<()> {
7272
if check_for_error() {
7373
Err(exceptions::ValueError::py_err("argument is wrong"))
7474
} else {
@@ -190,7 +190,7 @@ use pyo3::import_exception;
190190

191191
import_exception!(io, UnsupportedOperation);
192192

193-
fn tell(file: &PyAny) -> PyResult<u64> {
193+
fn tell(file: &PyObject) -> PyResult<u64> {
194194
use pyo3::exceptions::*;
195195

196196
let gil = Python::acquire_gil();

guide/src/function.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ You can use [`ObjectProtocol::is_callable`] to check if you have a callable obje
181181

182182
### Calling Rust functions in Python
183183

184-
If you have a static function, you can expose it with `#[pyfunction]` and use [`wrap_pyfunction!`] to get the corresponding [`PyAny`]. For dynamic functions, e.g. lambdas and functions that were passed as arguments, you must put them in some kind of owned container, e.g. a `Box`. (A long-term solution will be a special container similar to wasm-bindgen's `Closure`). You can then use a `#[pyclass]` struct with that container as a field as a way to pass the function over the FFI barrier. You can even make that class callable with `__call__` so it looks like a function in Python code.
184+
If you have a static function, you can expose it with `#[pyfunction]` and use [`wrap_pyfunction!`] to get the corresponding [`PyObject`]. For dynamic functions, e.g. lambdas and functions that were passed as arguments, you must put them in some kind of owned container, e.g. a `Box`. (A long-term solution will be a special container similar to wasm-bindgen's `Closure`). You can then use a `#[pyclass]` struct with that container as a field as a way to pass the function over the FFI barrier. You can even make that class callable with `__call__` so it looks like a function in Python code.
185185

186186
[`ObjectProtocol::is_callable`]: https://docs.rs/pyo3/latest/pyo3/trait.ObjectProtocol.html#tymethod.is_callable
187187
[`ObjectProtocol::call`]: https://docs.rs/pyo3/latest/pyo3/trait.ObjectProtocol.html#tymethod.call
188188
[`ObjectProtocol::call0`]: https://docs.rs/pyo3/latest/pyo3/trait.ObjectProtocol.html#tymethod.call0
189189
[`ObjectProtocol::call1`]: https://docs.rs/pyo3/latest/pyo3/trait.ObjectProtocol.html#tymethod.call1
190-
[`PyAny`]: https://docs.rs/pyo3/latest/pyo3/struct.PyAny
190+
[`PyObject`]: https://docs.rs/pyo3/latest/pyo3/struct.PyObject
191191
[`wrap_pyfunction!`]: https://docs.rs/pyo3/latest/pyo3/macro.wrap_pyfunction.html

guide/src/migration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ In addition, you can also extract `&PyCell<T>`, though you rarely need it.
121121

122122
Before:
123123
```ignore
124-
let obj: &PyAny = create_obj();
124+
let obj: &PyObject = create_obj();
125125
let obj_ref: &MyClass = obj.extract().unwrap();
126126
let obj_ref_mut: &mut MyClass = obj.extract().unwrap();
127127
```
@@ -137,7 +137,7 @@ After:
137137
# let typeobj = py.get_type::<MyClass>();
138138
# let d = [("c", typeobj)].into_py_dict(py);
139139
# let create_obj = || py.eval("c()", None, Some(d)).unwrap();
140-
let obj: &PyAny = create_obj();
140+
let obj: &PyObject = create_obj();
141141
let obj_cell: &PyCell<MyClass> = obj.extract().unwrap();
142142
let obj_cloned: MyClass = obj.extract().unwrap(); // extracted by cloning the object
143143
{

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: 10 additions & 10 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 [`Py::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.
@@ -46,11 +46,11 @@ references is done at runtime using `PyCell`, a scheme very similar to
4646

4747
## Object types
4848

49-
### `PyAny`
49+
### `PyObject`
5050

5151
**Represents:** a Python object of unspecified type, restricted to a GIL
52-
lifetime. Currently, `PyAny` can only ever occur as a reference, usually
53-
`&PyAny`.
52+
lifetime. Currently, `PyObject` can only ever occur as a reference, usually
53+
`&PyObject`.
5454

5555
**Used:** Whenever you want to refer to some Python object only as long as
5656
holding the GIL. For example, intermediate values and arguments to
@@ -83,15 +83,15 @@ or returning objects from functions implemented in Rust back to Python.
8383
### `PyTuple`, `PyDict`, and many more
8484

8585
**Represents:** a native Python object of known type, restricted to a GIL
86-
lifetime just like `PyAny`.
86+
lifetime just like `PyObject`.
8787

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

9292
**Conversions:**
9393

94-
- To `PyAny`: `obj.as_ref()`
94+
- To `PyObject`: `obj.as_ref()`
9595
- To `Py<T>`: `Py::from(obj)`
9696

9797

@@ -107,7 +107,7 @@ Rust references.
107107

108108
**Conversions:**
109109

110-
- From `PyAny`: `.downcast()`
110+
- From `PyObject`: `.downcast()`
111111

112112

113113
### `PyRef<SomeType>` and `PyRefMut<SomeType>`
@@ -116,7 +116,7 @@ Rust references.
116116
borrows, analog to `Ref` and `RefMut` used by `RefCell`.
117117

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

121121

122122

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

136136
[eval]: https://docs.rs/pyo3/latest/pyo3/struct.Python.html#method.eval
137137
[clone_ref]: https://docs.rs/pyo3/latest/pyo3/struct.Py.html#method.clone_ref
138-
[PyAny]: https://docs.rs/pyo3/latest/pyo3/types/struct.PyAny.html
138+
[PyObject]: https://docs.rs/pyo3/latest/pyo3/types/struct.PyObject.html
139139
[PyList_append]: https://docs.rs/pyo3/latest/pyo3/types/struct.PyList.html#method.append
140140
[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
pyo3::run_callback(_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, Py, PyAny, Python};
9+
use crate::{IntoPy, Py, PyObject, 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())

0 commit comments

Comments
 (0)