diff --git a/examples/rustapi_module/src/objstore.rs b/examples/rustapi_module/src/objstore.rs index 05e842e1e33..d36bbe00224 100644 --- a/examples/rustapi_module/src/objstore.rs +++ b/examples/rustapi_module/src/objstore.rs @@ -3,7 +3,7 @@ use pyo3::prelude::*; #[pyclass] #[derive(Default)] pub struct ObjStore { - obj: Vec>, + obj: Vec>, } #[pymethods] @@ -13,7 +13,7 @@ impl ObjStore { ObjStore::default() } - fn push(&mut self, py: Python, obj: &PyAny) { + fn push(&mut self, py: Python, obj: &PyObject) { self.obj.push(obj.to_object(py).into()); } } diff --git a/guide/src/class.md b/guide/src/class.md index 86d5a8ac6e4..3b9897b1728 100644 --- a/guide/src/class.md +++ b/guide/src/class.md @@ -32,8 +32,8 @@ impl pyo3::pyclass::PyClassAlloc for MyClass {} unsafe impl pyo3::PyTypeInfo for MyClass { type Type = MyClass; - type BaseType = PyAny; - type BaseLayout = pyo3::pycell::PyCellBase; + type BaseType = PyObject; + type BaseLayout = pyo3::pycell::PyCellBase; type Layout = PyCell; type Initializer = PyClassInitializer; type AsRefTarget = PyCell; @@ -54,11 +54,11 @@ unsafe impl pyo3::PyTypeInfo for MyClass { impl pyo3::pyclass::PyClass for MyClass { type Dict = pyo3::pyclass_slots::PyClassDummySlot; type WeakRef = pyo3::pyclass_slots::PyClassDummySlot; - type BaseNativeType = PyAny; + type BaseNativeType = PyObject; } -impl pyo3::IntoPy> for MyClass { - fn into_py(self, py: pyo3::Python) -> pyo3::Py { +impl pyo3::IntoPy> for MyClass { + fn into_py(self, py: pyo3::Python) -> pyo3::Py { pyo3::IntoPy::into_py(pyo3::Py::new(py, self).unwrap(), py) } } @@ -240,7 +240,7 @@ Consult the table below to determine which type your constructor should return: ## Inheritance -By default, `PyAny` is used as the base class. To override this default, +By default, `PyObject` is used as the base class. To override this default, use the `extends` parameter for `pyclass` with the full path to the base class. For convenience, `(T, U)` implements `Into>` where `U` is the @@ -340,7 +340,7 @@ impl DictWithCounter { fn new() -> Self { Self::default() } - fn set(mut self_: PyRefMut, key: String, value: &PyAny) -> PyResult<()> { + fn set(mut self_: PyRefMut, key: String, value: &PyObject) -> PyResult<()> { self_.counter.entry(key.clone()).or_insert(0); let py = self_.py(); let dict: &PyDict = unsafe { py.from_borrowed_ptr_or_err(self_.as_ptr())? }; @@ -498,7 +498,7 @@ impl MyClass { ``` Calls to these methods are protected by the GIL, so both `&self` and `&mut self` can be used. -The return type must be `PyResult` or `T` for some `T` that implements `IntoPy>`; +The return type must be `PyResult` or `T` for some `T` that implements `IntoPy>`; the latter is allowed if the method cannot raise Python exceptions. 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. This may be the type object of a derived class. * The first parameter implicitly has type `&PyType`. * For details on `parameter-list`, see the documentation of `Method arguments` section. -* The return type must be `PyResult` or `T` for some `T` that implements `IntoPy>`. +* The return type must be `PyResult` or `T` for some `T` that implements `IntoPy>`. ## Static methods To create a static method for a custom class, the method needs to be annotated with the `#[staticmethod]` attribute. The return type must be `T` or `PyResult` for some `T` that implements -`IntoPy>`. +`IntoPy>`. ```rust # use pyo3::prelude::*; @@ -699,7 +699,7 @@ The [`PyObjectProtocol`] trait provides several basic customizations. To customize object attribute access, define the following methods: - * `fn __getattr__(&self, name: FromPyObject) -> PyResult>>` + * `fn __getattr__(&self, name: FromPyObject) -> PyResult>>` * `fn __setattr__(&mut self, name: FromPyObject, value: FromPyObject) -> PyResult<()>` * `fn __delattr__(&mut self, name: FromPyObject) -> PyResult<()>` @@ -764,7 +764,7 @@ use pyo3::gc::{PyGCProtocol, PyVisit}; #[pyclass] struct ClassWithGCSupport { - obj: Option>, + obj: Option>, } #[pyproto] @@ -805,8 +805,8 @@ struct GCTracked {} // Fails because it does not implement PyGCProtocol Iterators can be defined using the [`PyIterProtocol`](https://docs.rs/pyo3/latest/pyo3/class/iter/trait.PyIterProtocol.html) trait. It includes two methods `__iter__` and `__next__`: - * `fn __iter__(slf: PyRefMut) -> PyResult>>` - * `fn __next__(slf: PyRefMut) -> PyResult>>>` + * `fn __iter__(slf: PyRefMut) -> PyResult>>` + * `fn __next__(slf: PyRefMut) -> PyResult>>>` Returning `Ok(None)` from `__next__` indicates that that there are no further items. These two methods can be take either `PyRef` or `PyRefMut` as their @@ -821,7 +821,7 @@ use pyo3::PyIterProtocol; #[pyclass] struct MyIterator { - iter: Box> + Send>, + iter: Box> + Send>, } #[pyproto] @@ -829,7 +829,7 @@ impl PyIterProtocol for MyIterator { fn __iter__(slf: PyRef) -> PyResult> { Ok(slf.into()) } - fn __next__(mut slf: PyRefMut) -> PyResult>> { + fn __next__(mut slf: PyRefMut) -> PyResult>> { Ok(slf.iter.next()) } } diff --git a/guide/src/conversions.md b/guide/src/conversions.md index 60f32f81c57..6c77f175321 100644 --- a/guide/src/conversions.md +++ b/guide/src/conversions.md @@ -27,7 +27,7 @@ and [`PyRefMut`]. They work like the reference wrappers of ## The `ToPyObject` trait [`ToPyObject`] is a conversion trait that allows various objects to be -converted into [`&PyAny`]. `IntoPy>` serves the +converted into [`&PyObject`]. `IntoPy>` serves the same purpose, except that it consumes `self`. @@ -48,7 +48,7 @@ use pyo3::types::{PyDict, PyTuple}; struct SomeObject; impl SomeObject { - fn new(py: Python) -> &PyAny { + fn new(py: Python) -> &PyObject { PyDict::new(py).to_object(py) } } @@ -89,7 +89,7 @@ use std::collections::HashMap; struct SomeObject; impl SomeObject { - fn new(py: Python) -> &PyAny { + fn new(py: Python) -> &PyObject { PyDict::new(py).to_object(py) } } @@ -135,7 +135,7 @@ Eventually, traits such as [`ToPyObject`] will be replaced by this trait and a [ [`FromPy`]: https://docs.rs/pyo3/latest/pyo3/trait.FromPy.html [`FromPyObject`]: https://docs.rs/pyo3/latest/pyo3/types/trait.FromPyObject.html [`ToPyObject`]: https://docs.rs/pyo3/latest/pyo3/trait.ToPyObject.html -[`PyAny`]: https://docs.rs/pyo3/latest/pyo3/struct.PyAny.html +[`PyObject`]: https://docs.rs/pyo3/latest/pyo3/struct.PyObject.html [`PyTuple`]: https://docs.rs/pyo3/latest/pyo3/types/struct.PyTuple.html [`ObjectProtocol`]: https://docs.rs/pyo3/latest/pyo3/trait.ObjectProtocol.html [`IntoPyDict`]: https://docs.rs/pyo3/latest/pyo3/types/trait.IntoPyDict.html diff --git a/guide/src/exception.md b/guide/src/exception.md index a2654710e64..87139d7b3a4 100644 --- a/guide/src/exception.md +++ b/guide/src/exception.md @@ -68,7 +68,7 @@ have Rust types as well. # use pyo3::exceptions; # use pyo3::prelude::*; # fn check_for_error() -> bool {false} -fn my_func(arg: &PyAny) -> PyResult<()> { +fn my_func(arg: &PyObject) -> PyResult<()> { if check_for_error() { Err(exceptions::ValueError::py_err("argument is wrong")) } else { @@ -190,7 +190,7 @@ use pyo3::import_exception; import_exception!(io, UnsupportedOperation); -fn tell(file: &PyAny) -> PyResult { +fn tell(file: &PyObject) -> PyResult { use pyo3::exceptions::*; let gil = Python::acquire_gil(); diff --git a/guide/src/function.md b/guide/src/function.md index 5551847e41c..091229741a5 100644 --- a/guide/src/function.md +++ b/guide/src/function.md @@ -181,11 +181,11 @@ You can use [`ObjectProtocol::is_callable`] to check if you have a callable obje ### Calling Rust functions in Python -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. +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. [`ObjectProtocol::is_callable`]: https://docs.rs/pyo3/latest/pyo3/trait.ObjectProtocol.html#tymethod.is_callable [`ObjectProtocol::call`]: https://docs.rs/pyo3/latest/pyo3/trait.ObjectProtocol.html#tymethod.call [`ObjectProtocol::call0`]: https://docs.rs/pyo3/latest/pyo3/trait.ObjectProtocol.html#tymethod.call0 [`ObjectProtocol::call1`]: https://docs.rs/pyo3/latest/pyo3/trait.ObjectProtocol.html#tymethod.call1 -[`PyAny`]: https://docs.rs/pyo3/latest/pyo3/struct.PyAny +[`PyObject`]: https://docs.rs/pyo3/latest/pyo3/struct.PyObject [`wrap_pyfunction!`]: https://docs.rs/pyo3/latest/pyo3/macro.wrap_pyfunction.html diff --git a/guide/src/migration.md b/guide/src/migration.md index 4035d89cfe8..87139e13d6c 100644 --- a/guide/src/migration.md +++ b/guide/src/migration.md @@ -121,7 +121,7 @@ In addition, you can also extract `&PyCell`, though you rarely need it. Before: ```ignore -let obj: &PyAny = create_obj(); +let obj: &PyObject = create_obj(); let obj_ref: &MyClass = obj.extract().unwrap(); let obj_ref_mut: &mut MyClass = obj.extract().unwrap(); ``` @@ -137,7 +137,7 @@ After: # let typeobj = py.get_type::(); # let d = [("c", typeobj)].into_py_dict(py); # let create_obj = || py.eval("c()", None, Some(d)).unwrap(); -let obj: &PyAny = create_obj(); +let obj: &PyObject = create_obj(); let obj_cell: &PyCell = obj.extract().unwrap(); let obj_cloned: MyClass = obj.extract().unwrap(); // extracted by cloning the object { diff --git a/guide/src/python_from_rust.md b/guide/src/python_from_rust.md index 24e1c3f6a6b..925943c0457 100644 --- a/guide/src/python_from_rust.md +++ b/guide/src/python_from_rust.md @@ -7,7 +7,7 @@ PyO3 is built for an extension module or not. [`Python::eval`](https://pyo3.rs/master/doc/pyo3/struct.Python.html#method.eval) is a method to execute a [Python expression](https://docs.python.org/3.7/reference/expressions.html) -and return the evaluated value as a `&PyAny` object. +and return the evaluated value as a `&PyObject` object. ```rust use pyo3::prelude::*; diff --git a/guide/src/rust_cpython.md b/guide/src/rust_cpython.md index d086e9e450c..24154fdc7a2 100644 --- a/guide/src/rust_cpython.md +++ b/guide/src/rust_cpython.md @@ -69,7 +69,7 @@ impl PyList { fn new(py: Python) -> &PyList {...} - fn get_item(&self, index: isize) -> &PyAny {...} + fn get_item(&self, index: isize) -> &PyObject {...} } ``` diff --git a/guide/src/types.md b/guide/src/types.md index f264fa711d5..3214d2f52ad 100644 --- a/guide/src/types.md +++ b/guide/src/types.md @@ -26,7 +26,7 @@ In PyO3, holding the GIL is modeled by acquiring a token of the type * It can be passed to functions that require a proof of holding the GIL, such as [`Py::clone_ref`][clone_ref]. * Its lifetime can be used to create Rust references that implicitly guarantee - holding the GIL, such as [`&'py PyAny`][PyAny]. + holding the GIL, such as [`&'py PyObject`][PyObject]. The latter two points are the reason why some APIs in PyO3 require the `py: Python` argument, while others don't. @@ -46,11 +46,11 @@ references is done at runtime using `PyCell`, a scheme very similar to ## Object types -### `PyAny` +### `PyObject` **Represents:** a Python object of unspecified type, restricted to a GIL -lifetime. Currently, `PyAny` can only ever occur as a reference, usually -`&PyAny`. +lifetime. Currently, `PyObject` can only ever occur as a reference, usually +`&PyObject`. **Used:** Whenever you want to refer to some Python object only as long as 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. ### `PyTuple`, `PyDict`, and many more **Represents:** a native Python object of known type, restricted to a GIL -lifetime just like `PyAny`. +lifetime just like `PyObject`. **Used:** Whenever you want to operate with native Python types while holding -the GIL. Like `PyAny`, this is the most convenient form to use for function +the GIL. Like `PyObject`, this is the most convenient form to use for function arguments and intermediate values. **Conversions:** -- To `PyAny`: `obj.as_ref()` +- To `PyObject`: `obj.as_ref()` - To `Py`: `Py::from(obj)` @@ -107,7 +107,7 @@ Rust references. **Conversions:** -- From `PyAny`: `.downcast()` +- From `PyObject`: `.downcast()` ### `PyRef` and `PyRefMut` @@ -116,7 +116,7 @@ Rust references. borrows, analog to `Ref` and `RefMut` used by `RefCell`. **Used:** while borrowing a `PyCell`. They can also be used with `.extract()` -on types like `Py` and `PyAny` to get a reference quickly. +on types like `Py` and `PyObject` to get a reference quickly. @@ -135,6 +135,6 @@ This trait marks structs that mirror native Python types, such as `PyList`. [eval]: https://docs.rs/pyo3/latest/pyo3/struct.Python.html#method.eval [clone_ref]: https://docs.rs/pyo3/latest/pyo3/struct.Py.html#method.clone_ref -[PyAny]: https://docs.rs/pyo3/latest/pyo3/types/struct.PyAny.html +[PyObject]: https://docs.rs/pyo3/latest/pyo3/types/struct.PyObject.html [PyList_append]: https://docs.rs/pyo3/latest/pyo3/types/struct.PyList.html#method.append [RefCell]: https://doc.rust-lang.org/std/cell/struct.RefCell.html diff --git a/pyo3-derive-backend/src/module.rs b/pyo3-derive-backend/src/module.rs index ffbb50e2bac..97bccfb20b0 100644 --- a/pyo3-derive-backend/src/module.rs +++ b/pyo3-derive-backend/src/module.rs @@ -178,7 +178,7 @@ pub fn add_fn_to_module( let wrapper = function_c_wrapper(&func.sig.ident, &spec); Ok(quote! { - fn #function_wrapper_ident(py: pyo3::Python) -> pyo3::Py { + fn #function_wrapper_ident(py: pyo3::Python) -> pyo3::Py { #wrapper let _def = pyo3::class::PyMethodDef { diff --git a/pyo3-derive-backend/src/pyclass.rs b/pyo3-derive-backend/src/pyclass.rs index d28fe85fc34..7183c12874a 100644 --- a/pyo3-derive-backend/src/pyclass.rs +++ b/pyo3-derive-backend/src/pyclass.rs @@ -43,7 +43,7 @@ impl Default for PyClassArgs { // We need the 0 as value for the constant we're later building using quote for when there // are no other flags flags: vec![parse_quote! { 0 }], - base: parse_quote! { pyo3::PyAny }, + base: parse_quote! { pyo3::PyObject }, has_extends: false, } } @@ -357,19 +357,19 @@ fn impl_class( let base_layout = if attr.has_extends { quote! { ::LayoutAsBase } } else { - quote! { pyo3::pycell::PyCellBase } + quote! { pyo3::pycell::PyCellBase } }; let base_nativetype = if attr.has_extends { quote! { ::BaseNativeType } } else { - quote! { pyo3::PyAny } + quote! { pyo3::PyObject } }; - // If #cls is not extended type, we allow Self->Py conversion + // If #cls is not extended type, we allow Self->Py conversion let into_pyobject = if !attr.has_extends { quote! { - impl pyo3::IntoPy> for #cls { - fn into_py(self, py: pyo3::Python) -> pyo3::Py { + impl pyo3::IntoPy> for #cls { + fn into_py(self, py: pyo3::Python) -> pyo3::Py { pyo3::IntoPy::into_py(pyo3::Py::new(py, self).unwrap(), py) } } diff --git a/pyo3-derive-backend/src/pymethod.rs b/pyo3-derive-backend/src/pymethod.rs index 3d19983e5a0..68733b462f6 100644 --- a/pyo3-derive-backend/src/pymethod.rs +++ b/pyo3-derive-backend/src/pymethod.rs @@ -377,7 +377,7 @@ pub(crate) fn impl_wrap_setter( pyo3::run_callback(_py, || { let _slf = _py.from_borrowed_ptr::>(_slf); #borrow_self - let _value = _py.from_borrowed_ptr::(_value); + let _value = _py.from_borrowed_ptr::(_value); let _val = pyo3::FromPyObject::extract(_value)?; pyo3::callback::convert(_py, {#setter_impl}) }) diff --git a/src/buffer.rs b/src/buffer.rs index cf9b5c1c135..477e0c9ed4d 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -18,7 +18,7 @@ //! `PyBuffer` implementation use crate::err::{self, PyResult}; -use crate::{exceptions, ffi, AsPyPointer, PyAny, Python}; +use crate::{exceptions, ffi, AsPyPointer, PyObject, Python}; use std::ffi::CStr; use std::os::raw; use std::pin::Pin; @@ -160,7 +160,7 @@ fn validate(b: &ffi::Py_buffer) { impl PyBuffer { /// Get the underlying buffer from the specified python object. - pub fn get(py: Python, obj: &PyAny) -> PyResult { + pub fn get(py: Python, obj: &PyObject) -> PyResult { unsafe { let mut buf = Box::pin(mem::zeroed::()); err::error_on_minusone( diff --git a/src/callback.rs b/src/callback.rs index bd2a0062c45..a4694dd1818 100644 --- a/src/callback.rs +++ b/src/callback.rs @@ -6,7 +6,7 @@ use crate::err::PyResult; use crate::exceptions::OverflowError; use crate::ffi::{self, Py_hash_t}; use crate::IntoPyPointer; -use crate::{IntoPy, Py, PyAny, Python}; +use crate::{IntoPy, Py, PyObject, Python}; use std::isize; use std::os::raw::c_int; @@ -48,7 +48,7 @@ where impl IntoPyCallbackOutput<*mut ffi::PyObject> for T where - T: IntoPy>, + T: IntoPy>, { fn convert(self, py: Python) -> PyResult<*mut ffi::PyObject> { Ok(self.into_py(py).into_ptr()) diff --git a/src/class/basic.rs b/src/class/basic.rs index 4d29f2e6bda..571e1e817c8 100644 --- a/src/class/basic.rs +++ b/src/class/basic.rs @@ -12,7 +12,7 @@ use crate::callback::HashCallbackOutput; use crate::class::methods::PyMethodDef; use crate::{ callback, exceptions, ffi, run_callback, FromPyObject, GILPool, IntoPy, ObjectProtocol, Py, - PyAny, PyCell, PyClass, PyErr, PyResult, + PyCell, PyClass, PyErr, PyObject, PyResult, }; use std::os::raw::c_int; @@ -103,7 +103,7 @@ pub trait PyObjectProtocol<'p>: PyClass { pub trait PyObjectGetAttrProtocol<'p>: PyObjectProtocol<'p> { type Name: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyObjectSetAttrProtocol<'p>: PyObjectProtocol<'p> { @@ -116,16 +116,16 @@ pub trait PyObjectDelAttrProtocol<'p>: PyObjectProtocol<'p> { type Result: Into>; } pub trait PyObjectStrProtocol<'p>: PyObjectProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyObjectReprProtocol<'p>: PyObjectProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyObjectFormatProtocol<'p>: PyObjectProtocol<'p> { type Format: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyObjectHashProtocol<'p>: PyObjectProtocol<'p> { @@ -135,12 +135,12 @@ pub trait PyObjectBoolProtocol<'p>: PyObjectProtocol<'p> { type Result: Into>; } pub trait PyObjectBytesProtocol<'p>: PyObjectProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyObjectRichcmpProtocol<'p>: PyObjectProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } @@ -232,7 +232,7 @@ where } let slf = py.from_borrowed_ptr::>(slf); - let arg = py.from_borrowed_ptr::(arg); + let arg = py.from_borrowed_ptr::(arg); callback::convert(py, call_ref!(slf, __getattr__, arg)) }) } @@ -488,7 +488,7 @@ where let py = pool.python(); run_callback(py, || { let slf = py.from_borrowed_ptr::>(slf); - let arg = py.from_borrowed_ptr::(arg); + let arg = py.from_borrowed_ptr::(arg); let borrowed_slf = slf.try_borrow()?; let op = extract_op(op)?; diff --git a/src/class/context.rs b/src/class/context.rs index e5b86c1efad..c6fb8c1eef3 100644 --- a/src/class/context.rs +++ b/src/class/context.rs @@ -6,7 +6,7 @@ use crate::class::methods::PyMethodDef; use crate::err::PyResult; -use crate::{Py, PyAny, PyClass}; +use crate::{Py, PyClass, PyObject}; /// Context manager interface #[allow(unused_variables)] @@ -32,7 +32,7 @@ pub trait PyContextProtocol<'p>: PyClass { } pub trait PyContextEnterProtocol<'p>: PyContextProtocol<'p> { - type Success: crate::IntoPy>; + type Success: crate::IntoPy>; type Result: Into>; } @@ -40,7 +40,7 @@ pub trait PyContextExitProtocol<'p>: PyContextProtocol<'p> { type ExcType: crate::FromPyObject<'p>; type ExcValue: crate::FromPyObject<'p>; type Traceback: crate::FromPyObject<'p>; - type Success: crate::IntoPy>; + type Success: crate::IntoPy>; type Result: Into>; } diff --git a/src/class/descr.rs b/src/class/descr.rs index 8c0360141f0..756f6426338 100644 --- a/src/class/descr.rs +++ b/src/class/descr.rs @@ -7,35 +7,35 @@ use crate::class::methods::PyMethodDef; use crate::err::PyResult; -use crate::types::{PyAny, PyType}; +use crate::types::{PyObject, PyType}; use crate::{ffi, FromPyObject, IntoPy, Py, PyClass}; use std::os::raw::c_int; /// Descriptor interface #[allow(unused_variables)] pub trait PyDescrProtocol<'p>: PyClass { - fn __get__(&'p self, instance: &'p PyAny, owner: Option<&'p PyType>) -> Self::Result + fn __get__(&'p self, instance: &'p PyObject, owner: Option<&'p PyType>) -> Self::Result where Self: PyDescrGetProtocol<'p>, { unimplemented!() } - fn __set__(&'p self, instance: &'p PyAny, value: &'p PyAny) -> Self::Result + fn __set__(&'p self, instance: &'p PyObject, value: &'p PyObject) -> Self::Result where Self: PyDescrSetProtocol<'p>, { unimplemented!() } - fn __delete__(&'p self, instance: &'p PyAny) -> Self::Result + fn __delete__(&'p self, instance: &'p PyObject) -> Self::Result where Self: PyDescrDeleteProtocol<'p>, { unimplemented!() } - fn __set_name__(&'p self, instance: &'p PyAny) -> Self::Result + fn __set_name__(&'p self, instance: &'p PyObject) -> Self::Result where Self: PyDescrSetNameProtocol<'p>, { @@ -46,7 +46,7 @@ pub trait PyDescrProtocol<'p>: PyClass { pub trait PyDescrGetProtocol<'p>: PyDescrProtocol<'p> { type Inst: FromPyObject<'p>; type Owner: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } diff --git a/src/class/iter.rs b/src/class/iter.rs index 89515b0710f..5532f76f584 100644 --- a/src/class/iter.rs +++ b/src/class/iter.rs @@ -5,7 +5,7 @@ use crate::callback::IntoPyCallbackOutput; use crate::derive_utils::TryFromPyCell; use crate::err::PyResult; -use crate::{ffi, IntoPy, IntoPyPointer, Py, PyAny, PyClass, Python}; +use crate::{ffi, IntoPy, IntoPyPointer, Py, PyClass, PyObject, Python}; /// Python Iterator Interface. /// @@ -30,13 +30,13 @@ pub trait PyIterProtocol<'p>: PyClass { pub trait PyIterIterProtocol<'p>: PyIterProtocol<'p> { type Receiver: TryFromPyCell<'p, Self>; - type Success: crate::IntoPy>; + type Success: crate::IntoPy>; type Result: Into>; } pub trait PyIterNextProtocol<'p>: PyIterProtocol<'p> { type Receiver: TryFromPyCell<'p, Self>; - type Success: crate::IntoPy>; + type Success: crate::IntoPy>; type Result: Into>>; } @@ -110,7 +110,7 @@ struct IterNextConverter(Option); impl IntoPyCallbackOutput<*mut ffi::PyObject> for IterNextConverter where - T: IntoPy>, + T: IntoPy>, { fn convert(self, py: Python) -> PyResult<*mut ffi::PyObject> { match self.0 { diff --git a/src/class/macros.rs b/src/class/macros.rs index f96611b7fdb..69d36f27b95 100644 --- a/src/class/macros.rs +++ b/src/class/macros.rs @@ -75,7 +75,7 @@ macro_rules! py_binary_func { let py = pool.python(); $crate::run_callback(py, || { let slf = py.from_borrowed_ptr::<$crate::PyCell>(slf); - let arg = py.from_borrowed_ptr::<$crate::PyAny>(arg); + let arg = py.from_borrowed_ptr::<$crate::PyObject>(arg); $crate::callback::convert(py, $call!(slf, $f, arg)$(.map($conv))?) }) } @@ -104,8 +104,8 @@ macro_rules! py_binary_num_func { let pool = $crate::GILPool::new(); let py = pool.python(); $crate::run_callback(py, || { - let lhs = py.from_borrowed_ptr::<$crate::PyAny>(lhs); - let rhs = py.from_borrowed_ptr::<$crate::PyAny>(rhs); + let lhs = py.from_borrowed_ptr::<$crate::PyObject>(lhs); + let rhs = py.from_borrowed_ptr::<$crate::PyObject>(rhs); let result = $class::$f(lhs.extract()?, rhs.extract()?).into(); $crate::callback::convert(py, result) @@ -132,7 +132,7 @@ macro_rules! py_binary_reverse_num_func { $crate::run_callback(py, || { // Swap lhs <-> rhs let slf = py.from_borrowed_ptr::<$crate::PyCell>(rhs); - let arg = py.from_borrowed_ptr::<$crate::PyAny>(lhs); + let arg = py.from_borrowed_ptr::<$crate::PyObject>(lhs); $crate::callback::convert( py, $class::$f(&*slf.try_borrow()?, arg.extract()?).into(), @@ -161,7 +161,7 @@ macro_rules! py_binary_self_func { let py = pool.python(); $crate::run_callback(py, || { let slf_ = py.from_borrowed_ptr::<$crate::PyCell>(slf); - let arg = py.from_borrowed_ptr::<$crate::PyAny>(arg); + let arg = py.from_borrowed_ptr::<$crate::PyObject>(arg); call_mut!(slf_, $f, arg)?; ffi::Py_INCREF(slf); Ok(slf) @@ -216,10 +216,10 @@ macro_rules! py_ternary_func { $crate::run_callback(py, || { let slf = py.from_borrowed_ptr::<$crate::PyCell>(slf); let arg1 = py - .from_borrowed_ptr::<$crate::types::PyAny>(arg1) + .from_borrowed_ptr::<$crate::types::PyObject>(arg1) .extract()?; let arg2 = py - .from_borrowed_ptr::<$crate::types::PyAny>(arg2) + .from_borrowed_ptr::<$crate::types::PyObject>(arg2) .extract()?; $crate::callback::convert(py, slf.try_borrow()?.$f(arg1, arg2).into()) @@ -251,13 +251,13 @@ macro_rules! py_ternary_num_func { let py = pool.python(); $crate::run_callback(py, || { let arg1 = py - .from_borrowed_ptr::<$crate::types::PyAny>(arg1) + .from_borrowed_ptr::<$crate::types::PyObject>(arg1) .extract()?; let arg2 = py - .from_borrowed_ptr::<$crate::types::PyAny>(arg2) + .from_borrowed_ptr::<$crate::types::PyObject>(arg2) .extract()?; let arg3 = py - .from_borrowed_ptr::<$crate::types::PyAny>(arg3) + .from_borrowed_ptr::<$crate::types::PyObject>(arg3) .extract()?; let result = $class::$f(arg1, arg2, arg3).into(); @@ -288,8 +288,8 @@ macro_rules! py_ternary_reverse_num_func { // Swap lhs <-> rhs let slf = py.from_borrowed_ptr::<$crate::PyCell>(arg2); let slf = slf.try_borrow()?; - let arg1 = py.from_borrowed_ptr::<$crate::PyAny>(arg1); - let arg2 = py.from_borrowed_ptr::<$crate::PyAny>(arg3); + let arg1 = py.from_borrowed_ptr::<$crate::PyObject>(arg1); + let arg2 = py.from_borrowed_ptr::<$crate::PyObject>(arg3); let result = $class::$f(&*slf, arg1.extract()?, arg2.extract()?).into(); $crate::callback::convert(py, result) }) @@ -318,7 +318,7 @@ macro_rules! py_dummy_ternary_self_func { let py = pool.python(); $crate::run_callback(py, || { let slf_cell = py.from_borrowed_ptr::<$crate::PyCell>(slf); - let arg1 = py.from_borrowed_ptr::<$crate::PyAny>(arg1); + let arg1 = py.from_borrowed_ptr::<$crate::PyObject>(arg1); call_mut!(slf_cell, $f, arg1)?; ffi::Py_INCREF(slf); Ok(slf) @@ -353,8 +353,8 @@ macro_rules! py_func_set { ), )) } else { - let name = py.from_borrowed_ptr::<$crate::PyAny>(name); - let value = py.from_borrowed_ptr::<$crate::PyAny>(value); + let name = py.from_borrowed_ptr::<$crate::PyObject>(name); + let value = py.from_borrowed_ptr::<$crate::PyObject>(value); crate::callback::convert(py, call_mut!(slf, $fn_set, name, value)) } }) @@ -382,7 +382,7 @@ macro_rules! py_func_del { if value.is_null() { let slf = py.from_borrowed_ptr::<$crate::PyCell>(slf); let name = py - .from_borrowed_ptr::<$crate::types::PyAny>(name) + .from_borrowed_ptr::<$crate::types::PyObject>(name) .extract()?; $crate::callback::convert(py, slf.try_borrow_mut()?.$fn_del(name).into()) } else { @@ -413,12 +413,12 @@ macro_rules! py_func_set_del { let py = pool.python(); $crate::run_callback(py, || { let slf = py.from_borrowed_ptr::<$crate::PyCell<$generic>>(slf); - let name = py.from_borrowed_ptr::<$crate::PyAny>(name); + let name = py.from_borrowed_ptr::<$crate::PyObject>(name); let result = if value.is_null() { call_mut!(slf, $fn_del, name) } else { - let value = py.from_borrowed_ptr::<$crate::PyAny>(value); + let value = py.from_borrowed_ptr::<$crate::PyObject>(value); call_mut!(slf, $fn_set, name, value) }; $crate::callback::convert(py, result) diff --git a/src/class/mapping.rs b/src/class/mapping.rs index 086b692cafe..a50839c9c9a 100644 --- a/src/class/mapping.rs +++ b/src/class/mapping.rs @@ -5,7 +5,7 @@ use crate::class::methods::PyMethodDef; use crate::err::{PyErr, PyResult}; -use crate::{exceptions, ffi, FromPyObject, IntoPy, Py, PyAny, PyClass}; +use crate::{exceptions, ffi, FromPyObject, IntoPy, Py, PyClass, PyObject}; /// Mapping interface #[allow(unused_variables)] @@ -55,7 +55,7 @@ pub trait PyMappingLenProtocol<'p>: PyMappingProtocol<'p> { pub trait PyMappingGetItemProtocol<'p>: PyMappingProtocol<'p> { type Key: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } @@ -71,7 +71,7 @@ pub trait PyMappingDelItemProtocol<'p>: PyMappingProtocol<'p> { } pub trait PyMappingReversedProtocol<'p>: PyMappingProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } diff --git a/src/class/number.rs b/src/class/number.rs index ce6a596321e..f99d279dc95 100644 --- a/src/class/number.rs +++ b/src/class/number.rs @@ -6,7 +6,7 @@ use crate::class::basic::PyObjectProtocolImpl; use crate::class::methods::PyMethodDef; use crate::err::PyResult; -use crate::{ffi, FromPyObject, IntoPy, Py, PyAny, PyClass}; +use crate::{ffi, FromPyObject, IntoPy, Py, PyClass, PyObject}; /// Number interface #[allow(unused_variables)] @@ -320,56 +320,56 @@ pub trait PyNumberProtocol<'p>: PyClass { pub trait PyNumberAddProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberSubProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberMulProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberMatmulProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberTruedivProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberFloordivProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberModProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberDivmodProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } @@ -377,127 +377,127 @@ pub trait PyNumberPowProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; type Modulo: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberLShiftProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRShiftProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberAndProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberXorProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberOrProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRAddProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRSubProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRMulProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRMatmulProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRTruedivProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRFloordivProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRModProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRDivmodProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRPowProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Modulo: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRLShiftProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRRShiftProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRAndProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRXorProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberROrProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } @@ -572,48 +572,48 @@ pub trait PyNumberIOrProtocol<'p>: PyNumberProtocol<'p> { } pub trait PyNumberNegProtocol<'p>: PyNumberProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberPosProtocol<'p>: PyNumberProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberAbsProtocol<'p>: PyNumberProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberInvertProtocol<'p>: PyNumberProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberComplexProtocol<'p>: PyNumberProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberIntProtocol<'p>: PyNumberProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberFloatProtocol<'p>: PyNumberProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PyNumberRoundProtocol<'p>: PyNumberProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type NDigits: FromPyObject<'p>; type Result: Into>; } pub trait PyNumberIndexProtocol<'p>: PyNumberProtocol<'p> { - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } diff --git a/src/class/pyasync.rs b/src/class/pyasync.rs index 727de4c281c..561ed586e9e 100644 --- a/src/class/pyasync.rs +++ b/src/class/pyasync.rs @@ -10,7 +10,7 @@ use crate::class::methods::PyMethodDef; use crate::err::PyResult; -use crate::{ffi, Py, PyAny, PyClass}; +use crate::{ffi, Py, PyClass, PyObject}; /// Python Async/Await support interface. /// @@ -59,22 +59,22 @@ pub trait PyAsyncProtocol<'p>: PyClass { } pub trait PyAsyncAwaitProtocol<'p>: PyAsyncProtocol<'p> { - type Success: crate::IntoPy>; + type Success: crate::IntoPy>; type Result: Into>; } pub trait PyAsyncAiterProtocol<'p>: PyAsyncProtocol<'p> { - type Success: crate::IntoPy>; + type Success: crate::IntoPy>; type Result: Into>; } pub trait PyAsyncAnextProtocol<'p>: PyAsyncProtocol<'p> { - type Success: crate::IntoPy>; + type Success: crate::IntoPy>; type Result: Into>>; } pub trait PyAsyncAenterProtocol<'p>: PyAsyncProtocol<'p> { - type Success: crate::IntoPy>; + type Success: crate::IntoPy>; type Result: Into>; } @@ -82,7 +82,7 @@ pub trait PyAsyncAexitProtocol<'p>: PyAsyncProtocol<'p> { type ExcType: crate::FromPyObject<'p>; type ExcValue: crate::FromPyObject<'p>; type Traceback: crate::FromPyObject<'p>; - type Success: crate::IntoPy>; + type Success: crate::IntoPy>; type Result: Into>; } @@ -194,13 +194,13 @@ mod anext { use crate::callback::IntoPyCallbackOutput; use crate::err::PyResult; use crate::Python; - use crate::{ffi, IntoPy, IntoPyPointer, Py, PyAny}; + use crate::{ffi, IntoPy, IntoPyPointer, Py, PyObject}; struct IterANextOutput(Option); impl IntoPyCallbackOutput<*mut ffi::PyObject> for IterANextOutput where - T: IntoPy>, + T: IntoPy>, { fn convert(self, py: Python) -> PyResult<*mut ffi::PyObject> { match self.0 { diff --git a/src/class/sequence.rs b/src/class/sequence.rs index c186d243ae8..e2187fb0800 100644 --- a/src/class/sequence.rs +++ b/src/class/sequence.rs @@ -7,7 +7,7 @@ use crate::conversion::{FromPyObject, IntoPy}; use crate::err::{PyErr, PyResult}; use crate::gil::GILPool; use crate::objectprotocol::ObjectProtocol; -use crate::{callback, exceptions, ffi, run_callback, Py, PyAny, PyCell, PyClass}; +use crate::{callback, exceptions, ffi, run_callback, Py, PyCell, PyClass, PyObject}; use std::os::raw::c_int; /// Sequence interface @@ -86,7 +86,7 @@ pub trait PySequenceLenProtocol<'p>: PySequenceProtocol<'p> { pub trait PySequenceGetItemProtocol<'p>: PySequenceProtocol<'p> { type Index: FromPyObject<'p> + From; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } @@ -108,22 +108,26 @@ pub trait PySequenceContainsProtocol<'p>: PySequenceProtocol<'p> { pub trait PySequenceConcatProtocol<'p>: PySequenceProtocol<'p> { type Other: FromPyObject<'p>; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } pub trait PySequenceRepeatProtocol<'p>: PySequenceProtocol<'p> { type Index: FromPyObject<'p> + From; - type Success: IntoPy>; + type Success: IntoPy>; type Result: Into>; } -pub trait PySequenceInplaceConcatProtocol<'p>: PySequenceProtocol<'p> + IntoPy> { +pub trait PySequenceInplaceConcatProtocol<'p>: + PySequenceProtocol<'p> + IntoPy> +{ type Other: FromPyObject<'p>; type Result: Into>; } -pub trait PySequenceInplaceRepeatProtocol<'p>: PySequenceProtocol<'p> + IntoPy> { +pub trait PySequenceInplaceRepeatProtocol<'p>: + PySequenceProtocol<'p> + IntoPy> +{ type Index: FromPyObject<'p> + From; type Result: Into>; } @@ -269,7 +273,7 @@ mod sq_ass_item_impl { } let mut slf = slf.try_borrow_mut()?; - let value = py.from_borrowed_ptr::(value); + let value = py.from_borrowed_ptr::(value); let value = value.extract()?; let result = slf.__setitem__(key.into(), value).into(); callback::convert(py, result) @@ -360,7 +364,7 @@ mod sq_ass_item_impl { let result = if value.is_null() { call_mut!(slf, __delitem__; key.into()) } else { - let value = py.from_borrowed_ptr::(value); + let value = py.from_borrowed_ptr::(value); let mut slf_ = slf.try_borrow_mut()?; let value = value.extract()?; slf_.__setitem__(key.into(), value).into() diff --git a/src/conversion.rs b/src/conversion.rs index e9b5e044b7a..e588a73a76d 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -4,7 +4,7 @@ use crate::err::{self, PyDowncastError, PyResult}; use crate::type_object::{PyDowncastImpl, PyTypeInfo}; use crate::types::PyTuple; -use crate::{ffi, gil, Py, PyAny, PyCell, PyClass, PyNativeType, PyRef, PyRefMut, Python}; +use crate::{ffi, gil, Py, PyCell, PyClass, PyNativeType, PyObject, PyRef, PyRefMut, Python}; use std::ptr::NonNull; /// This trait represents that **we can do zero-cost conversion from the object @@ -79,7 +79,7 @@ where /// Conversion trait that allows various objects to be converted into `PyObject`. pub trait ToPyObject { /// Converts self into a Python object. - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny; + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject; } /// This trait has two implementations: The slow one is implemented for @@ -154,12 +154,12 @@ where /// a Python object reference. /// /// Normal usage is through the helper methods `PyObject::extract` or -/// `PyAny::extract`: +/// `PyObject::extract`: /// -/// ```let obj: Py = ...; +/// ```let obj: Py = ...; /// let value: &TargetType = obj.extract(py)?; /// -/// let any: &PyAny = ...; +/// let any: &PyObject = ...; /// let value: &TargetType = any.extract()?; /// ``` /// @@ -174,23 +174,23 @@ where /// both the `obj` and `prepared` variables must outlive the resulting string slice. /// /// In cases where the result does not depend on the `'prepared` lifetime, -/// the inherent method `Py::extract()` can be used. +/// the inherent method `Py::extract()` can be used. /// -/// The trait's conversion method takes a `&PyAny` argument but is called +/// The trait's conversion method takes a `&PyObject` argument but is called /// `FromPyObject` for historical reasons. pub trait FromPyObject<'source>: Sized { - /// Extracts `Self` from the source `Py`. - fn extract(ob: &'source PyAny) -> PyResult; + /// Extracts `Self` from the source `Py`. + fn extract(ob: &'source PyObject) -> PyResult; } -/// Identity conversion: allows using existing `Py` instances where +/// Identity conversion: allows using existing `Py` instances where /// `T: ToPyObject` is expected. impl<'a, T: ?Sized> ToPyObject for &'a T where T: ToPyObject, { #[inline] - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { ::to_object(*self, py) } } @@ -201,7 +201,7 @@ impl ToPyObject for Option where T: ToPyObject, { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { match *self { Some(ref val) => val.to_object(py), None => py.None(), @@ -209,11 +209,11 @@ where } } -impl IntoPy> for Option +impl IntoPy> for Option where - T: IntoPy>, + T: IntoPy>, { - fn into_py(self, py: Python) -> Py { + fn into_py(self, py: Python) -> Py { match self { Some(val) => val.into_py(py), None => py.None().into(), @@ -223,23 +223,23 @@ where /// `()` is converted to Python `None`. impl ToPyObject for () { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { py.None() } } -impl FromPy<()> for Py { +impl FromPy<()> for Py { fn from_py(_: (), py: Python) -> Self { py.None().into() } } -impl<'a, T> FromPy<&'a T> for Py +impl<'a, T> FromPy<&'a T> for Py where T: AsPyPointer, { #[inline] - fn from_py(other: &'a T, _py: Python) -> Py { + fn from_py(other: &'a T, _py: Python) -> Py { unsafe { Py::from_borrowed_ptr(other.as_ptr()) } } } @@ -248,7 +248,7 @@ impl<'a, T> FromPyObject<'a> for &'a PyCell where T: PyClass, { - fn extract(obj: &'a PyAny) -> PyResult { + fn extract(obj: &'a PyObject) -> PyResult { PyTryFrom::try_from(obj).map_err(Into::into) } } @@ -257,7 +257,7 @@ impl<'a, T> FromPyObject<'a> for T where T: PyClass + Clone, { - fn extract(obj: &'a PyAny) -> PyResult { + fn extract(obj: &'a PyObject) -> PyResult { let cell: &PyCell = PyTryFrom::try_from(obj)?; Ok(unsafe { cell.try_borrow_unguarded()?.clone() }) } @@ -267,7 +267,7 @@ impl<'a, T> FromPyObject<'a> for PyRef<'a, T> where T: PyClass, { - fn extract(obj: &'a PyAny) -> PyResult { + fn extract(obj: &'a PyObject) -> PyResult { let cell: &PyCell = PyTryFrom::try_from(obj)?; cell.try_borrow().map_err(Into::into) } @@ -277,7 +277,7 @@ impl<'a, T> FromPyObject<'a> for PyRefMut<'a, T> where T: PyClass, { - fn extract(obj: &'a PyAny) -> PyResult { + fn extract(obj: &'a PyObject) -> PyResult { let cell: &PyCell = PyTryFrom::try_from(obj)?; cell.try_borrow_mut().map_err(Into::into) } @@ -287,7 +287,7 @@ impl<'a, T> FromPyObject<'a> for Option where T: FromPyObject<'a>, { - fn extract(obj: &'a PyAny) -> PyResult { + fn extract(obj: &'a PyObject) -> PyResult { if obj.as_ptr() == unsafe { ffi::Py_None() } { Ok(None) } else { @@ -300,33 +300,33 @@ where } /// Trait implemented by Python object types that allow a checked downcast. -/// If `T` implements `PyTryFrom`, we can convert `&PyAny` to `&T`. +/// If `T` implements `PyTryFrom`, we can convert `&PyObject` to `&T`. /// /// This trait is similar to `std::convert::TryFrom` pub trait PyTryFrom<'v>: Sized + PyDowncastImpl { - /// Cast from a concrete Python object type to Py. - fn try_from>(value: V) -> Result<&'v Self, PyDowncastError>; + /// Cast from a concrete Python object type to Py. + fn try_from>(value: V) -> Result<&'v Self, PyDowncastError>; - /// Cast from a concrete Python object type to Py. With exact type check. - fn try_from_exact>(value: V) -> Result<&'v Self, PyDowncastError>; + /// Cast from a concrete Python object type to Py. With exact type check. + fn try_from_exact>(value: V) -> Result<&'v Self, PyDowncastError>; - /// Cast a PyAny to a specific type of Py. The caller must + /// Cast a PyObject to a specific type of Py. The caller must /// have already verified the reference is for this type. - unsafe fn try_from_unchecked>(value: V) -> &'v Self; + unsafe fn try_from_unchecked>(value: V) -> &'v Self; } /// Trait implemented by Python object types that allow a checked downcast. /// This trait is similar to `std::convert::TryInto` pub trait PyTryInto: Sized { - /// Cast from Py to a concrete Python object type. + /// Cast from Py to a concrete Python object type. fn try_into(&self) -> Result<&T, PyDowncastError>; - /// Cast from Py to a concrete Python object type. With exact type check. + /// Cast from Py to a concrete Python object type. With exact type check. fn try_into_exact(&self) -> Result<&T, PyDowncastError>; } // TryFrom implies TryInto -impl PyTryInto for PyAny +impl PyTryInto for PyObject where U: for<'v> PyTryFrom<'v>, { @@ -342,7 +342,7 @@ impl<'v, T> PyTryFrom<'v> for T where T: PyDowncastImpl + PyTypeInfo + PyNativeType, { - fn try_from>(value: V) -> Result<&'v Self, PyDowncastError> { + fn try_from>(value: V) -> Result<&'v Self, PyDowncastError> { let value = value.into(); unsafe { if T::is_instance(value) { @@ -353,7 +353,7 @@ where } } - fn try_from_exact>(value: V) -> Result<&'v Self, PyDowncastError> { + fn try_from_exact>(value: V) -> Result<&'v Self, PyDowncastError> { let value = value.into(); unsafe { if T::is_exact_instance(value) { @@ -365,7 +365,7 @@ where } #[inline] - unsafe fn try_from_unchecked>(value: V) -> &'v Self { + unsafe fn try_from_unchecked>(value: V) -> &'v Self { Self::unchecked_downcast(value.into()) } } @@ -374,7 +374,7 @@ impl<'v, T> PyTryFrom<'v> for PyCell where T: 'v + PyClass, { - fn try_from>(value: V) -> Result<&'v Self, PyDowncastError> { + fn try_from>(value: V) -> Result<&'v Self, PyDowncastError> { let value = value.into(); unsafe { if T::is_instance(value) { @@ -384,7 +384,7 @@ where } } } - fn try_from_exact>(value: V) -> Result<&'v Self, PyDowncastError> { + fn try_from_exact>(value: V) -> Result<&'v Self, PyDowncastError> { let value = value.into(); unsafe { if T::is_exact_instance(value) { @@ -395,7 +395,7 @@ where } } #[inline] - unsafe fn try_from_unchecked>(value: V) -> &'v Self { + unsafe fn try_from_unchecked>(value: V) -> &'v Self { Self::unchecked_downcast(value.into()) } } diff --git a/src/derive_utils.rs b/src/derive_utils.rs index 49b427b55c3..ccfbbfcf562 100644 --- a/src/derive_utils.rs +++ b/src/derive_utils.rs @@ -9,7 +9,7 @@ use crate::exceptions::TypeError; use crate::instance::PyNativeType; use crate::pyclass::PyClass; use crate::pyclass_init::PyClassInitializer; -use crate::types::{PyAny, PyDict, PyModule, PyTuple}; +use crate::types::{PyDict, PyModule, PyObject, PyTuple}; use crate::{ffi, GILPool, IntoPy, Py, PyCell, Python}; use std::cell::UnsafeCell; @@ -39,7 +39,7 @@ pub fn parse_fn_args<'p>( kwargs: Option<&'p PyDict>, accept_args: bool, accept_kwargs: bool, - output: &mut [Option<&'p PyAny>], + output: &mut [Option<&'p PyObject>], ) -> PyResult<(&'p PyTuple, Option<&'p PyDict>)> { let nargs = args.len(); let mut used_args = 0; @@ -156,7 +156,7 @@ impl ModuleDef { } } -/// This trait wraps a T: IntoPy> into PyResult while PyResult remains PyResult. +/// This trait wraps a T: IntoPy> into PyResult while PyResult remains PyResult. /// /// This is necessary because proc macros run before typechecking and can't decide /// whether a return type is a (possibly aliased) PyResult or not. It is also quite handy because @@ -165,20 +165,20 @@ pub trait IntoPyResult { fn into_py_result(self) -> PyResult; } -impl>> IntoPyResult for T { +impl>> IntoPyResult for T { fn into_py_result(self) -> PyResult { Ok(self) } } -impl>> IntoPyResult for PyResult { +impl>> IntoPyResult for PyResult { fn into_py_result(self) -> PyResult { self } } /// Variant of IntoPyResult for the specific case of `#[new]`. In the case of returning (Sub, Base) -/// from `#[new]`, IntoPyResult can't apply because (Sub, Base) doesn't implement IntoPy>. +/// from `#[new]`, IntoPyResult can't apply because (Sub, Base) doesn't implement IntoPy>. pub trait IntoPyNewResult>> { fn into_pynew_result(self) -> PyResult; } @@ -197,20 +197,20 @@ impl>> IntoPyNewResult for PyRes #[doc(hidden)] pub trait GetPropertyValue { - fn get_property_value(&self, py: Python) -> Py; + fn get_property_value(&self, py: Python) -> Py; } impl GetPropertyValue for &T where - T: IntoPy> + Clone, + T: IntoPy> + Clone, { - fn get_property_value(&self, py: Python) -> Py { + fn get_property_value(&self, py: Python) -> Py { (*self).clone().into_py(py) } } -impl GetPropertyValue for Py { - fn get_property_value(&self, py: Python) -> Py { +impl GetPropertyValue for Py { + fn get_property_value(&self, py: Python) -> Py { self.clone_ref(py) } } diff --git a/src/err.rs b/src/err.rs index 669f1216084..1faa6002591 100644 --- a/src/err.rs +++ b/src/err.rs @@ -4,7 +4,7 @@ use crate::type_object::PyTypeObject; use crate::types::PyType; use crate::{exceptions, ffi}; use crate::{ - AsPyPointer, FromPy, IntoPy, IntoPyPointer, Py, PyAny, Python, ToBorrowedObject, ToPyObject, + AsPyPointer, FromPy, IntoPy, IntoPyPointer, Py, PyObject, Python, ToBorrowedObject, ToPyObject, }; use libc::c_int; use std::ffi::CString; @@ -21,7 +21,7 @@ use std::ptr::NonNull; /// call `Python::acquire_gil`. pub enum PyErrValue { None, - Value(Py), + Value(Py), ToArgs(Box), ToObject(Box), } @@ -40,13 +40,13 @@ pub struct PyErr { /// The value of the exception. /// - /// This can be either an instance of `Py`, a tuple of arguments to be passed to + /// This can be either an instance of `Py`, a tuple of arguments to be passed to /// `ptype`'s constructor, or a single argument to be passed to `ptype`'s constructor. Call /// `PyErr::to_object()` to get the exception instance in all cases. pub pvalue: PyErrValue, /// The `PyTraceBack` object associated with the error. - pub ptraceback: Option>, + pub ptraceback: Option>, } /// Represents the result of a Python call. @@ -58,7 +58,7 @@ pub struct PyDowncastError; /// Helper conversion trait that allows to use custom arguments for exception constructor. pub trait PyErrArguments { /// Arguments for exception - fn arguments(&self, _: Python) -> Py; + fn arguments(&self, _: Python) -> Py; } impl PyErr { @@ -133,7 +133,7 @@ impl PyErr { /// If `obj` is a Python exception type object, the PyErr will (lazily) create a new /// instance of that type. /// Otherwise, a `TypeError` is created instead. - pub fn from_instance(obj: &PyAny) -> PyErr { + pub fn from_instance(obj: &PyObject) -> PyErr { let ptr = obj.as_ptr(); if unsafe { ffi::PyExceptionInstance_Check(ptr) } != 0 { @@ -186,7 +186,7 @@ impl PyErr { _: Python<'p>, name: &str, base: Option<&PyType>, - dict: Option>, + dict: Option>, ) -> NonNull { let base: *mut ffi::PyObject = match base { None => std::ptr::null_mut(), @@ -312,7 +312,7 @@ impl PyErr { /// /// This method takes `mut self` because the error might need /// to be normalized in order to create the exception instance. - fn instance(mut self, py: Python) -> Py { + fn instance(mut self, py: Python) -> Py { self.normalize(py); match self.pvalue { PyErrValue::Value(ref instance) => instance.clone_ref(py), @@ -355,7 +355,7 @@ impl PyErr { /// Issues a warning message. /// May return a `PyErr` if warnings-as-errors is enabled. - pub fn warn(py: Python, category: &PyAny, message: &str, stacklevel: i32) -> PyResult<()> { + pub fn warn(py: Python, category: &PyObject, message: &str, stacklevel: i32) -> PyResult<()> { let message = CString::new(message)?; unsafe { error_on_minusone( @@ -396,21 +396,21 @@ impl std::fmt::Debug for PyErr { } } -impl FromPy for Py { +impl FromPy for Py { fn from_py(other: PyErr, py: Python) -> Self { other.instance(py) } } impl ToPyObject for PyErr { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { let err = self.clone_ref(py); err.instance(py).to_object(py) } } -impl<'a> IntoPy> for &'a PyErr { - fn into_py(self, py: Python) -> Py { +impl<'a> IntoPy> for &'a PyErr { + fn into_py(self, py: Python) -> Py { let err = self.clone_ref(py); err.instance(py) } @@ -449,7 +449,7 @@ impl std::convert::Into> for PyErr { macro_rules! impl_to_pyerr { ($err: ty, $pyexc: ty) => { impl PyErrArguments for $err { - fn arguments(&self, py: Python) -> Py { + fn arguments(&self, py: Python) -> Py { self.to_string().to_object(py).into() } } @@ -499,7 +499,7 @@ impl std::convert::From for PyErr { } impl PyErrArguments for io::Error { - fn arguments(&self, py: Python) -> Py { + fn arguments(&self, py: Python) -> Py { self.to_string().to_object(py).into() } } @@ -511,13 +511,13 @@ impl std::convert::From PyErrArguments for std::io::IntoInnerError { - fn arguments(&self, py: Python) -> Py { + fn arguments(&self, py: Python) -> Py { self.to_string().to_object(py).into() } } impl PyErrArguments for std::convert::Infallible { - fn arguments(&self, py: Python) -> Py { + fn arguments(&self, py: Python) -> Py { "Infalliable!".to_object(py).into() } } diff --git a/src/exceptions.rs b/src/exceptions.rs index 4d7d476840d..e496b358a06 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -5,7 +5,7 @@ use crate::err::{PyErr, PyResult}; use crate::ffi; use crate::type_object::PyTypeObject; -use crate::types::{PyAny, PyTuple}; +use crate::types::{PyObject, PyTuple}; use crate::Python; use crate::{AsPyPointer, ToPyObject}; use std::ffi::CStr; @@ -291,7 +291,7 @@ impl UnicodeDecodeError { input: &[u8], range: ops::Range, reason: &CStr, - ) -> PyResult<&'p PyAny> { + ) -> PyResult<&'p PyObject> { unsafe { let input: &[c_char] = &*(input as *const [u8] as *const [c_char]); py.from_owned_ptr_or_err(ffi::PyUnicodeDecodeError_Create( @@ -310,7 +310,7 @@ impl UnicodeDecodeError { py: Python<'p>, input: &[u8], err: std::str::Utf8Error, - ) -> PyResult<&'p PyAny> { + ) -> PyResult<&'p PyObject> { let pos = err.valid_up_to(); UnicodeDecodeError::new_err( py, diff --git a/src/ffi/setobject.rs b/src/ffi/setobject.rs index 6f9c832b4a6..8ad4b7cba46 100644 --- a/src/ffi/setobject.rs +++ b/src/ffi/setobject.rs @@ -41,14 +41,14 @@ pub unsafe fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyAnySet_CheckExact")] -pub unsafe fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyObjectSet_CheckExact")] +pub unsafe fn PyObjectSet_CheckExact(ob: *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PySet_Type || Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int } #[inline] -pub unsafe fn PyAnySet_Check(ob: *mut PyObject) -> c_int { - (PyAnySet_CheckExact(ob) != 0 +pub unsafe fn PyObjectSet_Check(ob: *mut PyObject) -> c_int { + (PyObjectSet_CheckExact(ob) != 0 || PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0 || PyType_IsSubtype(Py_TYPE(ob), &mut PyFrozenSet_Type) != 0) as c_int } diff --git a/src/gil.rs b/src/gil.rs index 5ff6f30700d..55d01f3141b 100644 --- a/src/gil.rs +++ b/src/gil.rs @@ -2,7 +2,7 @@ //! Interaction with python's global interpreter lock -use crate::{ffi, internal_tricks::Unsendable, PyAny, Python}; +use crate::{ffi, internal_tricks::Unsendable, PyObject, Python}; use std::cell::{Cell, UnsafeCell}; use std::{any, mem::ManuallyDrop, ptr::NonNull, sync}; @@ -275,14 +275,14 @@ pub unsafe fn register_pointer(obj: NonNull) { } } -pub unsafe fn register_owned(_py: Python, obj: NonNull) -> &PyAny { +pub unsafe fn register_owned(_py: Python, obj: NonNull) -> &PyObject { let pool = POOL.get_or_init(); - &*(pool.owned.push_back(obj) as *const _ as *const PyAny) + &*(pool.owned.push_back(obj) as *const _ as *const PyObject) } -pub unsafe fn register_borrowed(_py: Python, obj: NonNull) -> &PyAny { +pub unsafe fn register_borrowed(_py: Python, obj: NonNull) -> &PyObject { let pool = POOL.get_or_init(); - &*(pool.borrowed.push_back(obj) as *const _ as *const PyAny) + &*(pool.borrowed.push_back(obj) as *const _ as *const PyObject) } /// Increment pyo3's internal GIL count - to be called whenever GILPool or GILGuard is created. @@ -363,11 +363,9 @@ mod array_list { #[cfg(test)] mod test { use super::{GILPool, NonNull, GIL_COUNT, POOL}; - use crate::AsPyPointer; - use crate::Python; - use crate::{ffi, gil, Py, PyAny}; + use crate::{ffi, gil, AsPyPointer, Py, PyObject, Python}; - fn get_object() -> Py { + fn get_object() -> Py { // Convenience function for getting a single unique object let gil = Python::acquire_gil(); let py = gil.python(); diff --git a/src/instance.rs b/src/instance.rs index 6a6ffe5e2b2..352ed37de4d 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -4,8 +4,8 @@ use crate::gil; use crate::objectprotocol::ObjectProtocol; use crate::type_object::{PyBorrowFlagLayout, PyDowncastImpl}; use crate::{ - ffi, AsPyPointer, FromPy, FromPyObject, IntoPyPointer, PyAny, PyCell, PyClass, - PyClassInitializer, PyRef, PyRefMut, PyTypeInfo, Python, ToPyObject, + ffi, AsPyPointer, FromPy, FromPyObject, IntoPyPointer, PyCell, PyClass, PyClassInitializer, + PyObject, PyRef, PyRefMut, PyTypeInfo, Python, ToPyObject, }; use std::marker::PhantomData; use std::mem; @@ -278,7 +278,7 @@ impl Py { // } } -/// Retrieves `&'py` types from `Py` or `Py`. +/// Retrieves `&'py` types from `Py` or `Py`. /// /// # Examples /// `Py::as_ref` returns `&PyDict`, `&PyList` or so for native types, and `&PyCell` @@ -286,14 +286,14 @@ impl Py { /// ``` /// # use pyo3::prelude::*; /// use pyo3::ObjectProtocol; -/// let obj: Py = { +/// let obj: Py = { /// let gil = Python::acquire_gil(); /// let py = gil.python(); /// py.eval("[]", None, None).unwrap().to_object(py).into() /// }; /// let gil = Python::acquire_gil(); /// let py = gil.python(); -/// assert_eq!(obj.as_ref(py).len().unwrap(), 0); // PyAny implements ObjectProtocol +/// assert_eq!(obj.as_ref(py).len().unwrap(), 0); // PyObject implements ObjectProtocol /// ``` pub trait AsPyRef: Sized { type Target; @@ -307,18 +307,18 @@ where { type Target = T::AsRefTarget; fn as_ref<'p>(&'p self, _py: Python<'p>) -> &'p Self::Target { - let any = self as *const Py as *const PyAny; + let any = self as *const Py as *const PyObject; unsafe { PyDowncastImpl::unchecked_downcast(&*any) } } } impl ToPyObject for Py { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { unsafe { py.from_owned_ptr(self.clone_ref(py).into_ptr()) } } } -impl FromPy> for Py { +impl FromPy> for Py { /// Converts a `Py` instance to `PyObject`. /// Consumes `self` without calling `Py_DECREF()`. #[inline] @@ -403,8 +403,8 @@ where T: AsPyPointer, &'a T: 'a + FromPyObject<'a>, { - /// Extracts `Self` from the source `Py`. - fn extract(ob: &'a PyAny) -> PyResult { + /// Extracts `Self` from the source `Py`. + fn extract(ob: &'a PyObject) -> PyResult { unsafe { ob.extract::<&T>() .map(|val| Py::from_borrowed_ptr(val.as_ptr())) @@ -426,9 +426,9 @@ where /// ``` /// use pyo3::ffi; /// use pyo3::{ToPyObject, AsPyPointer, PyNativeType, ManagedPyRef}; -/// use pyo3::types::{PyDict, PyAny}; +/// use pyo3::types::{PyDict, PyObject}; /// -/// pub fn get_dict_item<'p>(dict: &'p PyDict, key: &impl ToPyObject) -> Option<&'p PyAny> { +/// pub fn get_dict_item<'p>(dict: &'p PyDict, key: &impl ToPyObject) -> Option<&'p PyObject> { /// let key = ManagedPyRef::from_to_pyobject(dict.py(), key); /// unsafe { /// dict.py().from_borrowed_ptr_or_opt(ffi::PyDict_GetItem(dict.as_ptr(), key.as_ptr())) diff --git a/src/lib.rs b/src/lib.rs index fd7c32e9bc7..e03a395fab2 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -148,8 +148,8 @@ pub use crate::pyclass::PyClass; pub use crate::pyclass_init::PyClassInitializer; pub use crate::python::{prepare_freethreaded_python, Python}; pub use crate::type_object::{type_flags, PyTypeInfo}; -// Since PyAny is as important as PyObject, we expose it to the top level. -pub use crate::types::PyAny; +// Since PyObject is as important as PyObject, we expose it to the top level. +pub use crate::types::PyObject; // Re-exported for wrap_function #[doc(hidden)] @@ -220,7 +220,7 @@ macro_rules! wrap_pyfunction { macro_rules! wrap_pymodule { ($module_name:ident) => {{ pyo3::paste::expr! { - &|_py| unsafe { pyo3::Py::::from_owned_ptr([]()) } + &|_py| unsafe { pyo3::Py::::from_owned_ptr([]()) } } }}; } diff --git a/src/marshal.rs b/src/marshal.rs index d0c7350b912..436c6e3b78f 100644 --- a/src/marshal.rs +++ b/src/marshal.rs @@ -1,5 +1,5 @@ use crate::ffi; -use crate::types::{PyAny, PyBytes}; +use crate::types::{PyBytes, PyObject}; use crate::{AsPyPointer, FromPyPointer, PyResult, Python}; use std::os::raw::{c_char, c_int}; @@ -35,7 +35,7 @@ pub fn dumps<'a>(py: Python<'a>, object: &impl AsPyPointer, version: i32) -> PyR } /// Deserialize an object from bytes using the Python built-in marshal module. -pub fn loads<'a, B>(py: Python<'a>, data: &B) -> PyResult<&'a PyAny> +pub fn loads<'a, B>(py: Python<'a>, data: &B) -> PyResult<&'a PyObject> where B: AsRef<[u8]> + ?Sized, { diff --git a/src/objectprotocol.rs b/src/objectprotocol.rs index dd88604f635..38323fd381e 100644 --- a/src/objectprotocol.rs +++ b/src/objectprotocol.rs @@ -3,7 +3,7 @@ use crate::class::basic::CompareOp; use crate::err::{self, PyDowncastError, PyErr, PyResult}; use crate::exceptions::TypeError; -use crate::types::{PyAny, PyDict, PyIterator, PyString, PyTuple, PyType}; +use crate::types::{PyDict, PyIterator, PyObject, PyString, PyTuple, PyType}; use crate::{ ffi, AsPyPointer, FromPyObject, IntoPy, IntoPyPointer, Py, PyNativeType, PyTryFrom, Python, ToBorrowedObject, ToPyObject, @@ -23,7 +23,7 @@ pub trait ObjectProtocol { /// Retrieves an attribute value. /// /// This is equivalent to the Python expression `self.attr_name`. - fn getattr(&self, attr_name: N) -> PyResult<&PyAny> + fn getattr(&self, attr_name: N) -> PyResult<&PyObject> where N: ToPyObject; @@ -69,7 +69,7 @@ pub trait ObjectProtocol { /// * CompareOp::Le: `self <= other` /// * CompareOp::Gt: `self > other` /// * CompareOp::Ge: `self >= other` - fn rich_compare(&self, other: O, compare_op: CompareOp) -> PyResult<&PyAny> + fn rich_compare(&self, other: O, compare_op: CompareOp) -> PyResult<&PyObject> where O: ToPyObject; @@ -89,17 +89,17 @@ pub trait ObjectProtocol { /// Calls the object. /// /// This is equivalent to the Python expression `self(*args, **kwargs)`. - fn call(&self, args: impl IntoPy>, kwargs: Option<&PyDict>) -> PyResult<&PyAny>; + fn call(&self, args: impl IntoPy>, kwargs: Option<&PyDict>) -> PyResult<&PyObject>; /// Calls the object with only positional arguments. /// /// This is equivalent to the Python expression `self(*args)`. - fn call1(&self, args: impl IntoPy>) -> PyResult<&PyAny>; + fn call1(&self, args: impl IntoPy>) -> PyResult<&PyObject>; /// Calls the object without arguments. /// /// This is equivalent to the Python expression `self()`. - fn call0(&self) -> PyResult<&PyAny>; + fn call0(&self) -> PyResult<&PyObject>; /// Calls a method on the object. /// @@ -122,17 +122,17 @@ pub trait ObjectProtocol { name: &str, args: impl IntoPy>, kwargs: Option<&PyDict>, - ) -> PyResult<&PyAny>; + ) -> PyResult<&PyObject>; /// Calls a method on the object with only positional arguments. /// /// This is equivalent to the Python expression `self.name(*args)`. - fn call_method1(&self, name: &str, args: impl IntoPy>) -> PyResult<&PyAny>; + fn call_method1(&self, name: &str, args: impl IntoPy>) -> PyResult<&PyObject>; /// Calls a method on the object without arguments. /// /// This is equivalent to the Python expression `self.name()`. - fn call_method0(&self, name: &str) -> PyResult<&PyAny>; + fn call_method0(&self, name: &str) -> PyResult<&PyObject>; /// Retrieves the hash code of the object. /// @@ -162,7 +162,7 @@ pub trait ObjectProtocol { /// Gets an item from the collections. /// /// This is equivalent to the Python expression `self[key]`. - fn get_item(&self, key: K) -> PyResult<&PyAny> + fn get_item(&self, key: K) -> PyResult<&PyObject> where K: ToBorrowedObject; @@ -199,7 +199,7 @@ pub trait ObjectProtocol { fn cast_as<'a, D>(&'a self) -> Result<&'a D, PyDowncastError> where D: PyTryFrom<'a>, - &'a PyAny: std::convert::From<&'a Self>; + &'a PyObject: std::convert::From<&'a Self>; /// Extracts some type from the Python object. /// @@ -207,19 +207,19 @@ pub trait ObjectProtocol { fn extract<'a, D>(&'a self) -> PyResult where D: FromPyObject<'a>, - &'a PyAny: std::convert::From<&'a Self>; + &'a PyObject: std::convert::From<&'a Self>; /// Returns the reference count for the Python object. fn get_refcnt(&self) -> isize; /// Gets the Python builtin value `None`. #[allow(non_snake_case)] // the Python keyword starts with uppercase - fn None(&self) -> &PyAny; + fn None(&self) -> &PyObject; } impl<'py, T> ObjectProtocol for T where - T: 'py + PyNativeType + AsPyPointer + AsRef, + T: 'py + PyNativeType + AsPyPointer + AsRef, { fn hasattr(&self, attr_name: N) -> PyResult where @@ -230,7 +230,7 @@ where }) } - fn getattr(&self, attr_name: N) -> PyResult<&PyAny> + fn getattr(&self, attr_name: N) -> PyResult<&PyObject> where N: ToPyObject, { @@ -301,7 +301,7 @@ where }) } - fn rich_compare(&self, other: O, compare_op: CompareOp) -> PyResult<&PyAny> + fn rich_compare(&self, other: O, compare_op: CompareOp) -> PyResult<&PyObject> where O: ToPyObject, { @@ -334,7 +334,7 @@ where unsafe { ffi::PyCallable_Check(self.as_ptr()) != 0 } } - fn call(&self, args: impl IntoPy>, kwargs: Option<&PyDict>) -> PyResult<&PyAny> { + fn call(&self, args: impl IntoPy>, kwargs: Option<&PyDict>) -> PyResult<&PyObject> { let args = args.into_py(self.py()).into_ptr(); let kwargs = kwargs.into_ptr(); let result = unsafe { @@ -348,11 +348,11 @@ where result } - fn call0(&self) -> PyResult<&PyAny> { + fn call0(&self) -> PyResult<&PyObject> { self.call((), None) } - fn call1(&self, args: impl IntoPy>) -> PyResult<&PyAny> { + fn call1(&self, args: impl IntoPy>) -> PyResult<&PyObject> { self.call(args, None) } @@ -361,7 +361,7 @@ where name: &str, args: impl IntoPy>, kwargs: Option<&PyDict>, - ) -> PyResult<&PyAny> { + ) -> PyResult<&PyObject> { name.with_borrowed_ptr(self.py(), |name| unsafe { let py = self.py(); let ptr = ffi::PyObject_GetAttr(self.as_ptr(), name); @@ -379,11 +379,11 @@ where }) } - fn call_method0(&self, name: &str) -> PyResult<&PyAny> { + fn call_method0(&self, name: &str) -> PyResult<&PyObject> { self.call_method(name, (), None) } - fn call_method1(&self, name: &str, args: impl IntoPy>) -> PyResult<&PyAny> { + fn call_method1(&self, name: &str, args: impl IntoPy>) -> PyResult<&PyObject> { self.call_method(name, args, None) } @@ -422,7 +422,7 @@ where self.len().map(|l| l == 0) } - fn get_item(&self, key: K) -> PyResult<&PyAny> + fn get_item(&self, key: K) -> PyResult<&PyObject> where K: ToBorrowedObject, { @@ -469,7 +469,7 @@ where fn cast_as<'a, D>(&'a self) -> Result<&'a D, PyDowncastError> where D: PyTryFrom<'a>, - &'a PyAny: std::convert::From<&'a Self>, + &'a PyObject: std::convert::From<&'a Self>, { D::try_from(self) } @@ -477,7 +477,7 @@ where fn extract<'a, D>(&'a self) -> PyResult where D: FromPyObject<'a>, - &'a PyAny: std::convert::From<&'a T>, + &'a PyObject: std::convert::From<&'a T>, { FromPyObject::extract(self.into()) } @@ -487,7 +487,7 @@ where } #[allow(non_snake_case)] // the Python keyword starts with uppercase - fn None(&self) -> &PyAny { + fn None(&self) -> &PyObject { unsafe { self.py().from_borrowed_ptr(ffi::Py_None()) } } } diff --git a/src/prelude.rs b/src/prelude.rs index ba3fcc9cd90..1a81f8366af 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -19,6 +19,6 @@ pub use crate::pyclass_init::PyClassInitializer; pub use crate::python::Python; pub use crate::{FromPy, FromPyObject, IntoPy, IntoPyPointer, PyTryFrom, PyTryInto, ToPyObject}; // PyModule is only part of the prelude because we need it for the pymodule function -pub use crate::types::{PyAny, PyModule}; +pub use crate::types::{PyModule, PyObject}; pub use pyo3cls::pymodule; pub use pyo3cls::{pyclass, pyfunction, pymethods, pyproto}; diff --git a/src/pycell.rs b/src/pycell.rs index 6349935e5ac..5dbf14b8cef 100644 --- a/src/pycell.rs +++ b/src/pycell.rs @@ -3,7 +3,7 @@ use crate::conversion::{AsPyPointer, FromPyPointer, ToPyObject}; use crate::pyclass_init::PyClassInitializer; use crate::pyclass_slots::{PyClassDict, PyClassWeakRef}; use crate::type_object::{PyBorrowFlagLayout, PyDowncastImpl, PyLayout, PySizedLayout, PyTypeInfo}; -use crate::{ffi, FromPy, Py, PyAny, PyClass, PyErr, PyNativeType, PyResult, Python}; +use crate::{ffi, FromPy, Py, PyClass, PyErr, PyNativeType, PyObject, PyResult, Python}; use std::cell::{Cell, UnsafeCell}; use std::fmt; use std::mem::ManuallyDrop; @@ -361,7 +361,7 @@ unsafe impl PyLayout for PyCell { } unsafe impl PyDowncastImpl for PyCell { - unsafe fn unchecked_downcast(obj: &PyAny) -> &Self { + unsafe fn unchecked_downcast(obj: &PyObject) -> &Self { &*(obj.as_ptr() as *const Self) } private_impl! {} @@ -374,7 +374,7 @@ impl AsPyPointer for PyCell { } impl ToPyObject for &PyCell { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { unsafe { py.from_borrowed_ptr(self.as_ptr()) } } } @@ -524,8 +524,8 @@ impl<'p, T: PyClass> Drop for PyRef<'p, T> { } } -impl<'p, T: PyClass> FromPy> for Py { - fn from_py(pyref: PyRef<'p, T>, _py: Python<'_>) -> Py { +impl<'p, T: PyClass> FromPy> for Py { + fn from_py(pyref: PyRef<'p, T>, _py: Python<'_>) -> Py { unsafe { Py::from_borrowed_ptr(pyref.inner.as_ptr()) } } } @@ -622,8 +622,8 @@ impl<'p, T: PyClass> Drop for PyRefMut<'p, T> { } } -impl<'p, T: PyClass> FromPy> for Py { - fn from_py(pyref: PyRefMut<'p, T>, _py: Python<'_>) -> Py { +impl<'p, T: PyClass> FromPy> for Py { + fn from_py(pyref: PyRefMut<'p, T>, _py: Python<'_>) -> Py { unsafe { Py::from_borrowed_ptr(pyref.inner.as_ptr()) } } } diff --git a/src/pyclass.rs b/src/pyclass.rs index 4f0f9ec194e..51228f0a6de 100644 --- a/src/pyclass.rs +++ b/src/pyclass.rs @@ -77,7 +77,7 @@ pub trait PyClass: type Dict: PyClassDict; /// Specify this class has `#[pyclass(weakref)]` or not. type WeakRef: PyClassWeakRef; - /// The closest native ancestor. This is `PyAny` by default, and when you declare + /// The closest native ancestor. This is `PyObject` by default, and when you declare /// `#[pyclass(extends=PyDict)]`, it's `PyDict`. type BaseNativeType: PyTypeInfo + PyNativeType; } diff --git a/src/python.rs b/src/python.rs index 5e9393202fc..76cf20e90a7 100644 --- a/src/python.rs +++ b/src/python.rs @@ -7,7 +7,7 @@ use crate::ffi; use crate::gil::{self, GILGuard}; use crate::instance::AsPyRef; use crate::type_object::{PyDowncastImpl, PyTypeInfo, PyTypeObject}; -use crate::types::{PyAny, PyDict, PyModule, PyType}; +use crate::types::{PyDict, PyModule, PyObject, PyType}; use crate::{AsPyPointer, FromPyPointer, IntoPyPointer, Py, PyTryFrom}; use std::ffi::CString; use std::marker::PhantomData; @@ -110,10 +110,10 @@ impl<'p> Python<'p> { /// /// **Note:** /// PyO3 types that represent objects with a lifetime tied to holding the GIL - /// cannot be used in the closure. This includes `&PyAny` and all the + /// cannot be used in the closure. This includes `&PyObject` and all the /// concrete-typed siblings, like `&PyString`. /// - /// You can convert such references to e.g. `Py` or `Py`, + /// You can convert such references to e.g. `Py` or `Py`, /// which makes them independent of the GIL lifetime. However, you cannot /// do much with those without a `Python<'p>` token, for which you'd need to /// reacquire the GIL. @@ -162,7 +162,7 @@ impl<'p> Python<'p> { code: &str, globals: Option<&PyDict>, locals: Option<&PyDict>, - ) -> PyResult<&'p PyAny> { + ) -> PyResult<&'p PyObject> { self.run_code(code, ffi::Py_eval_input, globals, locals) } @@ -215,7 +215,7 @@ impl<'p> Python<'p> { start: c_int, globals: Option<&PyDict>, locals: Option<&PyDict>, - ) -> PyResult<&'p PyAny> { + ) -> PyResult<&'p PyObject> { let code = CString::new(code)?; unsafe { let mptr = ffi::PyImport_AddModule("__main__\0".as_ptr() as *const _); @@ -274,21 +274,21 @@ impl<'p> Python<'p> { /// Gets the Python builtin value `None`. #[allow(non_snake_case)] // the Python keyword starts with uppercase #[inline] - pub fn None(self) -> &'p PyAny { + pub fn None(self) -> &'p PyObject { unsafe { self.from_borrowed_ptr(ffi::Py_None()) } } /// Gets the Python builtin value `NotImplemented`. #[allow(non_snake_case)] // the Python keyword starts with uppercase #[inline] - pub fn NotImplemented(self) -> &'p PyAny { + pub fn NotImplemented(self) -> &'p PyObject { unsafe { self.from_borrowed_ptr(ffi::Py_NotImplemented()) } } } impl<'p> Python<'p> { /// Registers the object in the release pool, and tries to downcast to specific type. - pub fn checked_cast_as(self, obj: Py) -> Result<&'p T, PyDowncastError> + pub fn checked_cast_as(self, obj: Py) -> Result<&'p T, PyDowncastError> where T: PyTryFrom<'p>, { @@ -298,7 +298,7 @@ impl<'p> Python<'p> { /// Registers the object in the release pool, and does an unchecked downcast /// to the specific type. - pub unsafe fn cast_as(self, obj: Py) -> &'p T + pub unsafe fn cast_as(self, obj: Py) -> &'p T where T: PyDowncastImpl + PyTypeInfo, { @@ -308,7 +308,7 @@ impl<'p> Python<'p> { /// Registers the object pointer in the release pool. #[allow(clippy::wrong_self_convention)] - pub unsafe fn from_borrowed_ptr_to_obj(self, ptr: *mut ffi::PyObject) -> &'p PyAny { + pub unsafe fn from_borrowed_ptr_to_obj(self, ptr: *mut ffi::PyObject) -> &'p PyObject { match NonNull::new(ptr) { Some(p) => gil::register_borrowed(self, p), None => crate::err::panic_after_error(), @@ -392,7 +392,7 @@ impl<'p> Python<'p> { unsafe { gil::register_any(ob) } } - /// Releases a Py reference. + /// Releases a Py reference. #[inline] pub fn release(self, ob: T) where @@ -416,7 +416,7 @@ impl<'p> Python<'p> { #[cfg(test)] mod test { use crate::objectprotocol::ObjectProtocol; - use crate::types::{IntoPyDict, PyAny, PyBool, PyInt, PyList}; + use crate::types::{IntoPyDict, PyBool, PyInt, PyList, PyObject}; use crate::Python; #[test] @@ -465,7 +465,7 @@ mod test { let gil = Python::acquire_gil(); let py = gil.python(); assert!(py - .is_instance::(PyBool::new(py, true).into()) + .is_instance::(PyBool::new(py, true).into()) .unwrap()); let list = PyList::new(py, &[1, 2, 3, 4]); assert!(!py.is_instance::(list.as_ref()).unwrap()); diff --git a/src/type_object.rs b/src/type_object.rs index 5069de176e0..77a95aeac9c 100644 --- a/src/type_object.rs +++ b/src/type_object.rs @@ -3,7 +3,7 @@ use crate::pyclass::{initialize_type_object, PyClass}; use crate::pyclass_init::PyObjectInit; -use crate::types::{PyAny, PyType}; +use crate::types::{PyObject, PyType}; use crate::{ffi, AsPyPointer, Py, Python}; use std::cell::UnsafeCell; use std::ptr::NonNull; @@ -11,7 +11,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; /// `T: PyLayout` represents that `T` is a concrete representaion of `U` in Python heap. /// E.g., `PyCell` is a concrete representaion of all `pyclass`es, and `ffi::PyObject` -/// is of `PyAny`. +/// is of `PyObject`. /// /// This trait is intended to be used internally. pub unsafe trait PyLayout { @@ -65,17 +65,17 @@ pub mod type_flags { /// Reference abstraction for `PyClass` and `PyNativeType`. Used internaly. // NOTE(kngwyu): -// `&PyCell` is a pointer of `ffi::PyObject` but `&PyAny` is a pointer of a pointer, +// `&PyCell` is a pointer of `ffi::PyObject` but `&PyObject` is a pointer of a pointer, // so we need abstraction. // This mismatch eventually should be fixed(e.g., https://github.com/PyO3/pyo3/issues/679). pub unsafe trait PyDowncastImpl { - /// Cast `&PyAny` to `&Self` without no type checking. + /// Cast `&PyObject` to `&Self` without no type checking. /// /// # Safety /// /// Unless obj is not an instance of a type corresponding to Self, /// this method causes undefined behavior. - unsafe fn unchecked_downcast(obj: &PyAny) -> &Self; + unsafe fn unchecked_downcast(obj: &PyObject) -> &Self; private_decl! {} } @@ -83,7 +83,7 @@ unsafe impl<'py, T> PyDowncastImpl for T where T: 'py + crate::PyNativeType, { - unsafe fn unchecked_downcast(obj: &PyAny) -> &Self { + unsafe fn unchecked_downcast(obj: &PyObject) -> &Self { &*(obj as *const _ as *const Self) } private_impl! {} @@ -130,14 +130,14 @@ pub unsafe trait PyTypeInfo: Sized { fn type_object() -> &'static ffi::PyTypeObject; /// Check if `*mut ffi::PyObject` is instance of this type - fn is_instance(object: &PyAny) -> bool { + fn is_instance(object: &PyObject) -> bool { unsafe { ffi::PyObject_TypeCheck(object.as_ptr(), Self::type_object() as *const _ as _) != 0 } } /// Check if `*mut ffi::PyObject` is exact instance of this type - fn is_exact_instance(object: &PyAny) -> bool { + fn is_exact_instance(object: &PyObject) -> bool { unsafe { (*object.as_ptr()).ob_type == Self::type_object() as *const _ as _ } } } diff --git a/src/types/any.rs b/src/types/any.rs index 5edbec0efb6..987f5a3b6ee 100644 --- a/src/types/any.rs +++ b/src/types/any.rs @@ -5,11 +5,11 @@ use std::ptr::NonNull; /// A Python object with GIL lifetime /// -/// Represents any Python object. All Python objects can be cast to `PyAny`. +/// Represents any Python object. All Python objects can be cast to `PyObject`. /// In addition, if the inner object is an instance of type `T`, we can downcast -/// `PyAny` into `T`. +/// `PyObject` into `T`. /// -/// `PyAny` is used as a reference with a lifetime that represents that the GIL +/// `PyObject` is used as a reference with a lifetime that represents that the GIL /// is held, therefore its API does not require a `Python<'py>` token. /// /// See [the guide](https://pyo3.rs/master/types.html) for an explanation @@ -19,29 +19,29 @@ use std::ptr::NonNull; /// /// ``` /// use pyo3::prelude::*; -/// use pyo3::types::{PyAny, PyDict, PyList}; +/// use pyo3::types::{PyObject, PyDict, PyList}; /// let gil = Python::acquire_gil(); /// let dict = PyDict::new(gil.python()); -/// assert!(gil.python().is_instance::(dict).unwrap()); +/// assert!(gil.python().is_instance::(dict).unwrap()); /// let any = dict.as_ref(); /// assert!(any.downcast::().is_ok()); /// assert!(any.downcast::().is_err()); /// ``` #[repr(transparent)] -pub struct PyAny(NonNull); -unsafe impl crate::type_object::PyLayout for ffi::PyObject {} -impl crate::type_object::PySizedLayout for ffi::PyObject {} -pyobject_native_type_named!(PyAny); +pub struct PyObject(NonNull); +unsafe impl crate::type_object::PyLayout for ffi::PyObject {} +impl crate::type_object::PySizedLayout for ffi::PyObject {} +pyobject_native_type_named!(PyObject); pyobject_native_type_convert!( - PyAny, + PyObject, ffi::PyObject, ffi::PyBaseObject_Type, Some("builtins"), ffi::PyObject_Check ); -pyobject_native_type_extract!(PyAny); +pyobject_native_type_extract!(PyObject); -impl PyAny { +impl PyObject { pub fn downcast(&self) -> Result<&T, PyDowncastError> where for<'py> T: PyTryFrom<'py>, diff --git a/src/types/boolobject.rs b/src/types/boolobject.rs index fb131c039f9..d07287fe07a 100644 --- a/src/types/boolobject.rs +++ b/src/types/boolobject.rs @@ -1,12 +1,12 @@ // Copyright (c) 2017-present PyO3 Project and Contributors use crate::{ - ffi, AsPyPointer, FromPy, FromPyObject, IntoPy, Py, PyAny, PyResult, PyTryFrom, Python, + ffi, AsPyPointer, FromPy, FromPyObject, IntoPy, Py, PyObject, PyResult, PyTryFrom, Python, ToPyObject, }; /// Represents a Python `bool`. #[repr(transparent)] -pub struct PyBool(PyAny); +pub struct PyBool(PyObject); pyobject_native_type!(PyBool, ffi::PyObject, ffi::PyBool_Type, ffi::PyBool_Check); @@ -27,7 +27,7 @@ impl PyBool { /// Converts a Rust `bool` to a Python `bool`. impl ToPyObject for bool { #[inline] - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { unsafe { py.from_borrowed_ptr(if *self { ffi::Py_True() @@ -38,7 +38,7 @@ impl ToPyObject for bool { } } -impl FromPy for Py { +impl FromPy for Py { #[inline] fn from_py(other: bool, py: Python) -> Self { PyBool::new(py, other).into_py(py) @@ -49,7 +49,7 @@ impl FromPy for Py { /// /// Fails with `TypeError` if the input is not a Python `bool`. impl<'source> FromPyObject<'source> for bool { - fn extract(obj: &'source PyAny) -> PyResult { + fn extract(obj: &'source PyObject) -> PyResult { Ok(::try_from(obj)?.is_true()) } } @@ -57,7 +57,7 @@ impl<'source> FromPyObject<'source> for bool { #[cfg(test)] mod test { use crate::objectprotocol::ObjectProtocol; - use crate::types::{PyAny, PyBool}; + use crate::types::{PyBool, PyObject}; use crate::Python; use crate::ToPyObject; @@ -66,7 +66,7 @@ mod test { let gil = Python::acquire_gil(); let py = gil.python(); assert!(PyBool::new(py, true).is_true()); - let t: &PyAny = PyBool::new(py, true).into(); + let t: &PyObject = PyBool::new(py, true).into(); assert_eq!(true, t.extract::().unwrap()); assert_eq!(true.to_object(py), PyBool::new(py, true).as_ref()); } @@ -76,7 +76,7 @@ mod test { let gil = Python::acquire_gil(); let py = gil.python(); assert!(!PyBool::new(py, false).is_true()); - let t: &PyAny = PyBool::new(py, false).into(); + let t: &PyObject = PyBool::new(py, false).into(); assert_eq!(false, t.extract().unwrap()); assert_eq!(false.to_object(py), PyBool::new(py, false).as_ref()); } diff --git a/src/types/bytearray.rs b/src/types/bytearray.rs index f4ae74e851a..4b77b257ef6 100644 --- a/src/types/bytearray.rs +++ b/src/types/bytearray.rs @@ -3,13 +3,13 @@ use crate::err::{PyErr, PyResult}; use crate::ffi; use crate::instance::PyNativeType; use crate::AsPyPointer; -use crate::{PyAny, Python}; +use crate::{PyObject, Python}; use std::os::raw::c_char; use std::slice; /// Represents a Python `bytearray`. #[repr(transparent)] -pub struct PyByteArray(PyAny); +pub struct PyByteArray(PyObject); pyobject_native_var_type!(PyByteArray, ffi::PyByteArray_Type, ffi::PyByteArray_Check); diff --git a/src/types/bytes.rs b/src/types/bytes.rs index a3fbda3c0c9..067fff1e750 100644 --- a/src/types/bytes.rs +++ b/src/types/bytes.rs @@ -1,5 +1,5 @@ use crate::{ - ffi, AsPyPointer, FromPy, FromPyObject, IntoPy, Py, PyAny, PyResult, PyTryFrom, Python, + ffi, AsPyPointer, FromPy, FromPyObject, IntoPy, Py, PyObject, PyResult, PyTryFrom, Python, }; use std::ops::Index; use std::os::raw::c_char; @@ -10,7 +10,7 @@ use std::str; /// /// This type is immutable. #[repr(transparent)] -pub struct PyBytes(PyAny); +pub struct PyBytes(PyObject); pyobject_native_var_type!(PyBytes, ffi::PyBytes_Type, ffi::PyBytes_Check); @@ -56,14 +56,14 @@ impl> Index for PyBytes { } } -impl<'a> FromPy<&'a [u8]> for Py { +impl<'a> FromPy<&'a [u8]> for Py { fn from_py(other: &'a [u8], py: Python) -> Self { PyBytes::new(py, other).into_py(py) } } impl<'a> FromPyObject<'a> for &'a [u8] { - fn extract(obj: &'a PyAny) -> PyResult { + fn extract(obj: &'a PyObject) -> PyResult { Ok(::try_from(obj)?.as_bytes()) } } diff --git a/src/types/complex.rs b/src/types/complex.rs index 0db41212b1f..307c1d1e47c 100644 --- a/src/types/complex.rs +++ b/src/types/complex.rs @@ -2,14 +2,14 @@ use crate::ffi; #[cfg(not(PyPy))] use crate::instance::PyNativeType; use crate::AsPyPointer; -use crate::{PyAny, Python}; +use crate::{PyObject, Python}; #[cfg(not(PyPy))] use std::ops::*; use std::os::raw::c_double; /// Represents a Python `complex`. #[repr(transparent)] -pub struct PyComplex(PyAny); +pub struct PyComplex(PyObject); pyobject_native_type!( PyComplex, @@ -131,7 +131,7 @@ impl<'py> Neg for &'py PyComplex { #[cfg(feature = "num-complex")] mod complex_conversion { use super::*; - use crate::{FromPyObject, Py, PyAny, PyErr, PyResult, ToPyObject}; + use crate::{FromPyObject, PyErr, PyObject, PyResult, ToPyObject, Py}; use num_complex::Complex; impl PyComplex { @@ -150,7 +150,7 @@ mod complex_conversion { ($float: ty) => { impl ToPyObject for Complex<$float> { #[inline] - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { unsafe { let raw_obj = ffi::PyComplex_FromDoubles(self.re as c_double, self.im as c_double); @@ -158,15 +158,15 @@ mod complex_conversion { } } } - impl crate::IntoPy> for Complex<$float> { - fn into_py(self, py: Python) -> Py { + impl crate::IntoPy> for Complex<$float> { + fn into_py(self, py: Python) -> Py { self.to_object(py).into() } } #[cfg(not(Py_LIMITED_API))] #[allow(clippy::float_cmp)] // The comparison is for an error value impl<'source> FromPyObject<'source> for Complex<$float> { - fn extract(obj: &'source PyAny) -> PyResult> { + fn extract(obj: &'source PyObject) -> PyResult> { unsafe { let val = ffi::PyComplex_AsCComplex(obj.as_ptr()); if val.real == -1.0 && PyErr::occurred(obj.py()) { @@ -180,7 +180,7 @@ mod complex_conversion { #[cfg(Py_LIMITED_API)] #[allow(clippy::float_cmp)] // The comparison is for an error value impl<'source> FromPyObject<'source> for Complex<$float> { - fn extract(obj: &'source PyAny) -> PyResult> { + fn extract(obj: &'source PyObject) -> PyResult> { unsafe { let ptr = obj.as_ptr(); let real = ffi::PyComplex_RealAsDouble(ptr); diff --git a/src/types/datetime.rs b/src/types/datetime.rs index 9063521beb8..b19a520ecc9 100644 --- a/src/types/datetime.rs +++ b/src/types/datetime.rs @@ -28,7 +28,7 @@ use crate::ffi::{ use crate::types::PyTuple; use crate::AsPyPointer; use crate::ToPyObject; -use crate::{PyAny, Python}; +use crate::{PyObject, Python}; use std::os::raw::c_int; #[cfg(not(PyPy))] use std::ptr; @@ -64,7 +64,7 @@ pub trait PyTimeAccess { } /// Bindings around `datetime.date` -pub struct PyDate(PyAny); +pub struct PyDate(PyObject); pyobject_native_type!( PyDate, crate::ffi::PyDateTime_Date, @@ -120,7 +120,7 @@ impl PyDateAccess for PyDate { } /// Bindings for `datetime.datetime` -pub struct PyDateTime(PyAny); +pub struct PyDateTime(PyObject); pyobject_native_type!( PyDateTime, crate::ffi::PyDateTime_DateTime, @@ -139,7 +139,7 @@ impl PyDateTime { minute: u8, second: u8, microsecond: u32, - tzinfo: Option<&PyAny>, + tzinfo: Option<&PyObject>, ) -> PyResult<&'p PyDateTime> { unsafe { let ptr = (PyDateTimeAPI.DateTime_FromDateAndTime)( @@ -230,7 +230,7 @@ impl PyTimeAccess for PyDateTime { } /// Bindings for `datetime.time` -pub struct PyTime(PyAny); +pub struct PyTime(PyObject); pyobject_native_type!( PyTime, crate::ffi::PyDateTime_Time, @@ -246,7 +246,7 @@ impl PyTime { minute: u8, second: u8, microsecond: u32, - tzinfo: Option<&PyAny>, + tzinfo: Option<&PyObject>, ) -> PyResult<&'p PyTime> { unsafe { let ptr = (PyDateTimeAPI.Time_FromTime)( @@ -271,7 +271,7 @@ impl PyTime { minute: u8, second: u8, microsecond: u32, - tzinfo: Option<&PyAny>, + tzinfo: Option<&PyObject>, fold: bool, ) -> PyResult<&'p PyTime> { unsafe { @@ -315,7 +315,7 @@ impl PyTimeAccess for PyTime { /// Bindings for `datetime.tzinfo` /// /// This is an abstract base class and should not be constructed directly. -pub struct PyTzInfo(PyAny); +pub struct PyTzInfo(PyObject); pyobject_native_type!( PyTzInfo, crate::ffi::PyObject, @@ -325,7 +325,7 @@ pyobject_native_type!( ); /// Bindings for `datetime.timedelta` -pub struct PyDelta(PyAny); +pub struct PyDelta(PyObject); pyobject_native_type!( PyDelta, crate::ffi::PyDateTime_Delta, @@ -370,7 +370,7 @@ impl PyDeltaAccess for PyDelta { } // Utility function -unsafe fn opt_to_pyobj(py: Python, opt: Option<&PyAny>) -> *mut ffi::PyObject { +unsafe fn opt_to_pyobj(py: Python, opt: Option<&PyObject>) -> *mut ffi::PyObject { // Convenience function for unpacking Options to either an Object or None match opt { Some(tzi) => tzi.as_ptr(), diff --git a/src/types/dict.rs b/src/types/dict.rs index b269d19a9f3..f88f763e320 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -2,7 +2,7 @@ use crate::err::{self, PyErr, PyResult}; use crate::instance::PyNativeType; -use crate::types::{PyAny, PyList}; +use crate::types::{PyList, PyObject}; use crate::AsPyPointer; #[cfg(not(PyPy))] use crate::IntoPyPointer; @@ -15,7 +15,7 @@ use std::{cmp, collections, hash}; /// Represents a Python `dict`. #[repr(transparent)] -pub struct PyDict(PyAny); +pub struct PyDict(PyObject); pyobject_native_type!( PyDict, @@ -38,7 +38,7 @@ impl PyDict { /// Returns an error on invalid input. In the case of key collisions, /// this keeps the last entry seen. #[cfg(not(PyPy))] - pub fn from_sequence<'p>(py: Python<'p>, seq: &PyAny) -> PyResult<&'p PyDict> { + pub fn from_sequence<'p>(py: Python<'p>, seq: &PyObject) -> PyResult<&'p PyDict> { unsafe { let dict = py.from_owned_ptr::(ffi::PyDict_New()); match ffi::PyDict_MergeFromSeq2(dict.into_ptr(), seq.into_ptr(), 1i32) { @@ -97,7 +97,7 @@ impl PyDict { /// Returns `None` if the item is not present, or if an error occurs. /// /// To get a `KeyError` for non-existing keys, use `ObjectProtocol::get_item`. - pub fn get_item(&self, key: K) -> Option<&PyAny> + pub fn get_item(&self, key: K) -> Option<&PyObject> where K: ToBorrowedObject, { @@ -177,12 +177,12 @@ impl PyDict { } pub struct PyDictIterator<'py> { - dict: &'py PyAny, + dict: &'py PyObject, pos: isize, } impl<'py> Iterator for PyDictIterator<'py> { - type Item = (&'py PyAny, &'py PyAny); + type Item = (&'py PyObject, &'py PyObject); #[inline] fn next(&mut self) -> Option { @@ -200,7 +200,7 @@ impl<'py> Iterator for PyDictIterator<'py> { } impl<'a> std::iter::IntoIterator for &'a PyDict { - type Item = (&'a PyAny, &'a PyAny); + type Item = (&'a PyObject, &'a PyObject); type IntoIter = PyDictIterator<'a>; fn into_iter(self) -> Self::IntoIter { @@ -214,7 +214,7 @@ where V: ToPyObject, H: hash::BuildHasher, { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { IntoPyDict::into_py_dict(self, py).into() } } @@ -224,18 +224,18 @@ where K: cmp::Eq + ToPyObject, V: ToPyObject, { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { IntoPyDict::into_py_dict(self, py).into() } } -impl IntoPy> for collections::HashMap +impl IntoPy> for collections::HashMap where - K: hash::Hash + cmp::Eq + IntoPy>, - V: IntoPy>, + K: hash::Hash + cmp::Eq + IntoPy>, + V: IntoPy>, H: hash::BuildHasher, { - fn into_py(self, py: Python) -> Py { + fn into_py(self, py: Python) -> Py { let iter = self .into_iter() .map(|(k, v)| (k.into_py(py), v.into_py(py))); @@ -243,12 +243,12 @@ where } } -impl IntoPy> for collections::BTreeMap +impl IntoPy> for collections::BTreeMap where - K: cmp::Eq + IntoPy>, - V: IntoPy>, + K: cmp::Eq + IntoPy>, + V: IntoPy>, { - fn into_py(self, py: Python) -> Py { + fn into_py(self, py: Python) -> Py { let iter = self .into_iter() .map(|(k, v)| (k.into_py(py), v.into_py(py))); @@ -323,7 +323,7 @@ where V: FromPyObject<'source>, S: hash::BuildHasher + Default, { - fn extract(ob: &'source PyAny) -> Result { + fn extract(ob: &'source PyObject) -> Result { let dict = ::try_from(ob)?; let mut ret = HashMap::default(); for (k, v) in dict.iter() { @@ -338,7 +338,7 @@ where K: FromPyObject<'source> + cmp::Ord, V: FromPyObject<'source>, { - fn extract(ob: &'source PyAny) -> Result { + fn extract(ob: &'source PyObject) -> Result { let dict = ::try_from(ob)?; let mut ret = BTreeMap::new(); for (k, v) in dict.iter() { diff --git a/src/types/floatob.rs b/src/types/floatob.rs index b84beda30e2..ab2826796a1 100644 --- a/src/types/floatob.rs +++ b/src/types/floatob.rs @@ -2,8 +2,8 @@ // // based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython use crate::{ - ffi, AsPyPointer, FromPy, FromPyObject, IntoPy, ObjectProtocol, Py, PyAny, PyErr, PyNativeType, - PyResult, Python, ToPyObject, + ffi, AsPyPointer, FromPy, FromPyObject, IntoPy, ObjectProtocol, Py, PyErr, PyNativeType, + PyObject, PyResult, Python, ToPyObject, }; use std::os::raw::c_double; @@ -14,7 +14,7 @@ use std::os::raw::c_double; /// and [extract](struct.PyObject.html#method.extract) /// with `f32`/`f64`. #[repr(transparent)] -pub struct PyFloat(PyAny); +pub struct PyFloat(PyObject); pyobject_native_type!( PyFloat, @@ -36,12 +36,12 @@ impl PyFloat { } impl ToPyObject for f64 { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { PyFloat::new(py, *self).into() } } -impl FromPy for Py { +impl FromPy for Py { fn from_py(other: f64, py: Python) -> Self { PyFloat::new(py, other).into_py(py) } @@ -50,7 +50,7 @@ impl FromPy for Py { impl<'source> FromPyObject<'source> for f64 { // PyFloat_AsDouble returns -1.0 upon failure #![cfg_attr(feature = "cargo-clippy", allow(clippy::float_cmp))] - fn extract(obj: &'source PyAny) -> PyResult { + fn extract(obj: &'source PyObject) -> PyResult { let v = unsafe { ffi::PyFloat_AsDouble(obj.as_ptr()) }; if v == -1.0 && PyErr::occurred(obj.py()) { @@ -62,19 +62,19 @@ impl<'source> FromPyObject<'source> for f64 { } impl ToPyObject for f32 { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { PyFloat::new(py, f64::from(*self)).into() } } -impl FromPy for Py { +impl FromPy for Py { fn from_py(other: f32, py: Python) -> Self { PyFloat::new(py, f64::from(other)).into_py(py) } } impl<'source> FromPyObject<'source> for f32 { - fn extract(obj: &'source PyAny) -> PyResult { + fn extract(obj: &'source PyObject) -> PyResult { Ok(obj.extract::()? as f32) } } diff --git a/src/types/iterator.rs b/src/types/iterator.rs index 1697340f735..446bdc6e777 100644 --- a/src/types/iterator.rs +++ b/src/types/iterator.rs @@ -2,7 +2,7 @@ // // based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython -use crate::{ffi, AsPyPointer, PyAny, PyDowncastError, PyErr, PyNativeType, PyResult, Python}; +use crate::{ffi, AsPyPointer, PyDowncastError, PyErr, PyNativeType, PyObject, PyResult, Python}; /// A Python iterator object. /// @@ -25,7 +25,7 @@ use crate::{ffi, AsPyPointer, PyAny, PyDowncastError, PyErr, PyNativeType, PyRes /// # Ok(()) /// # } /// ``` -pub struct PyIterator<'p>(&'p PyAny); +pub struct PyIterator<'p>(&'p PyObject); impl<'p> PyIterator<'p> { /// Constructs a `PyIterator` from a Python iterator object. @@ -52,7 +52,7 @@ impl<'p> PyIterator<'p> { } impl<'p> Iterator for PyIterator<'p> { - type Item = PyResult<&'p PyAny>; + type Item = PyResult<&'p PyObject>; /// Retrieves the next item from an iterator. /// @@ -88,7 +88,7 @@ mod tests { use crate::gil::{GILGuard, GILPool}; use crate::objectprotocol::ObjectProtocol; use crate::types::{PyDict, PyList}; - use crate::{AsPyRef, Py, PyAny, Python, ToPyObject}; + use crate::{AsPyRef, Py, PyObject, Python, ToPyObject}; use indoc::indoc; #[test] @@ -104,7 +104,7 @@ mod tests { #[test] fn iter_refcnt() { - let obj: Py; + let obj: Py; let count; { let gil_guard = Python::acquire_gil(); @@ -128,8 +128,8 @@ mod tests { let gil_guard = Python::acquire_gil(); let py = gil_guard.python(); - let obj: Py; - let none: Py; + let obj: Py; + let none: Py; let count; { let _pool = unsafe { GILPool::new() }; diff --git a/src/types/list.rs b/src/types/list.rs index dae52de6b10..8950fb6d9d1 100644 --- a/src/types/list.rs +++ b/src/types/list.rs @@ -5,13 +5,13 @@ use crate::err::{self, PyResult}; use crate::ffi::{self, Py_ssize_t}; use crate::{ - AsPyPointer, IntoPy, IntoPyPointer, Py, PyAny, PyNativeType, Python, ToBorrowedObject, + AsPyPointer, IntoPy, IntoPyPointer, Py, PyNativeType, PyObject, Python, ToBorrowedObject, ToPyObject, }; /// Represents a Python `list`. #[repr(transparent)] -pub struct PyList(PyAny); +pub struct PyList(PyObject); pyobject_native_var_type!(PyList, ffi::PyList_Type, ffi::PyList_Check); @@ -53,7 +53,7 @@ impl PyList { /// Gets the item at the specified index. /// /// Panics if the index is out of range. - pub fn get_item(&self, index: isize) -> &PyAny { + pub fn get_item(&self, index: isize) -> &PyObject { unsafe { self.py() .from_borrowed_ptr(ffi::PyList_GetItem(self.as_ptr(), index as Py_ssize_t)) @@ -63,7 +63,7 @@ impl PyList { /// Gets the item at the specified index. /// /// Panics if the index is out of range. - pub fn get_parked_item(&self, index: isize) -> Py { + pub fn get_parked_item(&self, index: isize) -> Py { unsafe { Py::from_borrowed_ptr(ffi::PyList_GetItem(self.as_ptr(), index as Py_ssize_t)) } } @@ -130,10 +130,10 @@ pub struct PyListIterator<'a> { } impl<'a> Iterator for PyListIterator<'a> { - type Item = &'a PyAny; + type Item = &'a PyObject; #[inline] - fn next(&mut self) -> Option<&'a PyAny> { + fn next(&mut self) -> Option<&'a PyObject> { if self.index < self.list.len() as isize { let item = self.list.get_item(self.index); self.index += 1; @@ -145,7 +145,7 @@ impl<'a> Iterator for PyListIterator<'a> { } impl<'a> std::iter::IntoIterator for &'a PyList { - type Item = &'a PyAny; + type Item = &'a PyObject; type IntoIter = PyListIterator<'a>; fn into_iter(self) -> Self::IntoIter { @@ -157,7 +157,7 @@ impl ToPyObject for [T] where T: ToPyObject, { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { unsafe { let ptr = ffi::PyList_New(self.len() as Py_ssize_t); for (i, e) in self.iter().enumerate() { @@ -172,11 +172,11 @@ where macro_rules! array_impls { ($($N:expr),+) => { $( - impl IntoPy> for [T; $N] + impl IntoPy> for [T; $N] where T: ToPyObject { - fn into_py(self, py: Python) -> Py { + fn into_py(self, py: Python) -> Py { self.as_ref().to_object(py).into() } } @@ -193,16 +193,16 @@ impl ToPyObject for Vec where T: ToPyObject, { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { self.as_slice().to_object(py) } } -impl IntoPy> for Vec +impl IntoPy> for Vec where - T: IntoPy>, + T: IntoPy>, { - fn into_py(self, py: Python) -> Py { + fn into_py(self, py: Python) -> Py { unsafe { let ptr = ffi::PyList_New(self.len() as Py_ssize_t); for (i, e) in self.into_iter().enumerate() { diff --git a/src/types/mod.rs b/src/types/mod.rs index f8ea43b8687..5c2101b5e24 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -2,7 +2,7 @@ //! Various types defined by the Python interpreter such as `int`, `str` and `tuple`. -pub use self::any::PyAny; +pub use self::any::PyObject; pub use self::boolobject::PyBool; pub use self::bytearray::PyByteArray; pub use self::bytes::PyBytes; @@ -28,10 +28,10 @@ pub use self::typeobject::PyType; #[macro_export] macro_rules! pyobject_native_type_named ( ($name: ty $(,$type_param: ident)*) => { - impl<$($type_param,)*> ::std::convert::AsRef<$crate::PyAny> for $name { + impl<$($type_param,)*> ::std::convert::AsRef<$crate::PyObject> for $name { #[inline] - fn as_ref(&self) -> &$crate::PyAny { - unsafe{&*(self as *const $name as *const $crate::PyAny)} + fn as_ref(&self) -> &$crate::PyObject { + unsafe{&*(self as *const $name as *const $crate::PyObject)} } } @@ -71,9 +71,9 @@ macro_rules! pyobject_native_type { pyobject_native_type_convert!($name, $layout, $typeobject, $module, $checkfunction $(,$type_param)*); pyobject_native_type_extract!($name $(,$type_param)*); - impl<'a, $($type_param,)*> ::std::convert::From<&'a $name> for &'a $crate::PyAny { + impl<'a, $($type_param,)*> ::std::convert::From<&'a $name> for &'a $crate::PyObject { fn from(ob: &'a $name) -> Self { - unsafe{&*(ob as *const $name as *const $crate::PyAny)} + unsafe{&*(ob as *const $name as *const $crate::PyObject)} } } }; @@ -93,9 +93,9 @@ macro_rules! pyobject_native_var_type { $typeobject, $module, $checkfunction $(,$type_param)*); pyobject_native_type_extract!($name $(,$type_param)*); - impl<'a, $($type_param,)*> ::std::convert::From<&'a $name> for &'a $crate::PyAny { + impl<'a, $($type_param,)*> ::std::convert::From<&'a $name> for &'a $crate::PyObject { fn from(ob: &'a $name) -> Self { - unsafe{&*(ob as *const $name as *const $crate::PyAny)} + unsafe{&*(ob as *const $name as *const $crate::PyObject)} } } }; @@ -111,7 +111,7 @@ macro_rules! pyobject_native_var_type { macro_rules! pyobject_native_type_extract { ($name: ty $(,$type_param: ident)*) => { impl<'py, $($type_param,)*> $crate::FromPyObject<'py> for &'py $name { - fn extract(obj: &'py $crate::PyAny) -> $crate::PyResult { + fn extract(obj: &'py $crate::PyObject) -> $crate::PyResult { $crate::PyTryFrom::try_from(obj).map_err(Into::into) } } @@ -124,7 +124,7 @@ macro_rules! pyobject_native_type_convert( $module: expr, $checkfunction: path $(,$type_param: ident)*) => { unsafe impl<$($type_param,)*> $crate::type_object::PyTypeInfo for $name { type Type = (); - type BaseType = $crate::PyAny; + type BaseType = $crate::PyObject; type Layout = $layout; type BaseLayout = ffi::PyObject; type Initializer = $crate::pyclass_init::PyNativeTypeInitializer; @@ -139,7 +139,7 @@ macro_rules! pyobject_native_type_convert( } #[allow(unused_unsafe)] - fn is_instance(ptr: &$crate::PyAny) -> bool { + fn is_instance(ptr: &$crate::PyObject) -> bool { use $crate::AsPyPointer; unsafe { $checkfunction(ptr.as_ptr()) > 0 } } @@ -148,7 +148,7 @@ macro_rules! pyobject_native_type_convert( impl<$($type_param,)*> $crate::ToPyObject for $name { #[inline] - fn to_object<'p>(&self, py: $crate::Python<'p>) -> &'p $crate::PyAny { + fn to_object<'p>(&self, py: $crate::Python<'p>) -> &'p $crate::PyObject { unsafe { py.from_borrowed_ptr(self.0.as_ptr()) } } } diff --git a/src/types/module.rs b/src/types/module.rs index 3d88c8ba7a3..ca52f3dd2b9 100644 --- a/src/types/module.rs +++ b/src/types/module.rs @@ -10,7 +10,7 @@ use crate::objectprotocol::ObjectProtocol; use crate::pyclass::PyClass; use crate::type_object::PyTypeObject; use crate::types::PyTuple; -use crate::types::{PyAny, PyDict, PyList}; +use crate::types::{PyDict, PyList, PyObject}; use crate::{AsPyPointer, AsPyRef, IntoPy, Py, Python, ToPyObject}; use std::ffi::{CStr, CString}; use std::os::raw::c_char; @@ -18,7 +18,7 @@ use std::str; /// Represents a Python `module` object. #[repr(transparent)] -pub struct PyModule(PyAny); +pub struct PyModule(PyObject); pyobject_native_var_type!(PyModule, ffi::PyModule_Type, ffi::PyModule_Check); @@ -127,28 +127,28 @@ impl PyModule { name: &str, args: impl IntoPy>, kwargs: Option<&PyDict>, - ) -> PyResult<&PyAny> { + ) -> PyResult<&PyObject> { self.getattr(name)?.call(args, kwargs) } /// Calls a function in the module with only positional arguments. /// /// This is equivalent to the Python expression `module.name(*args)`. - pub fn call1(&self, name: &str, args: impl IntoPy>) -> PyResult<&PyAny> { + pub fn call1(&self, name: &str, args: impl IntoPy>) -> PyResult<&PyObject> { self.getattr(name)?.call1(args) } /// Calls a function in the module without arguments. /// /// This is equivalent to the Python expression `module.name()`. - pub fn call0(&self, name: &str) -> PyResult<&PyAny> { + pub fn call0(&self, name: &str) -> PyResult<&PyObject> { self.getattr(name)?.call0() } /// Gets a member from the module. /// /// This is equivalent to the Python expression `module.name`. - pub fn get(&self, name: &str) -> PyResult<&PyAny> { + pub fn get(&self, name: &str) -> PyResult<&PyObject> { self.getattr(name) } @@ -192,7 +192,7 @@ impl PyModule { /// ```rust,ignore /// m.add("also_double", wrap_pyfunction!(double)(py)); /// ``` - pub fn add_wrapped(&self, wrapper: &impl Fn(Python) -> Py) -> PyResult<()> { + pub fn add_wrapped(&self, wrapper: &impl Fn(Python) -> Py) -> PyResult<()> { let function = wrapper(self.py()); let name = function .as_ref(self.py()) diff --git a/src/types/num.rs b/src/types/num.rs index cbf7de4b9d6..5f203805dbd 100644 --- a/src/types/num.rs +++ b/src/types/num.rs @@ -3,8 +3,8 @@ // based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython use crate::{ - exceptions, ffi, AsPyPointer, FromPyObject, IntoPy, Py, PyAny, PyErr, PyNativeType, PyResult, - Python, ToPyObject, + exceptions, ffi, AsPyPointer, FromPyObject, IntoPy, Py, PyErr, PyNativeType, PyObject, + PyResult, Python, ToPyObject, }; use num_traits::cast::cast; use std::i64; @@ -26,18 +26,18 @@ macro_rules! int_fits_larger_int { ($rust_type:ty, $larger_type:ty) => { impl ToPyObject for $rust_type { #[inline] - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { (*self as $larger_type).to_object(py) } } - impl IntoPy> for $rust_type { - fn into_py(self, py: Python) -> Py { + impl IntoPy> for $rust_type { + fn into_py(self, py: Python) -> Py { (self as $larger_type).into_py(py) } } impl<'source> FromPyObject<'source> for $rust_type { - fn extract(obj: &'source PyAny) -> PyResult { + fn extract(obj: &'source PyObject) -> PyResult { let val = $crate::objectprotocol::ObjectProtocol::extract::<$larger_type>(obj)?; match cast::<$larger_type, $rust_type>(val) { Some(v) => Ok(v), @@ -59,7 +59,7 @@ macro_rules! int_convert_128 { ($rust_type: ty, $byte_size: expr, $is_signed: expr) => { impl ToPyObject for $rust_type { #[inline] - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { unsafe { let bytes = self.to_ne_bytes(); let obj = ffi::_PyLong_FromByteArray( @@ -72,13 +72,13 @@ macro_rules! int_convert_128 { } } } - impl IntoPy> for $rust_type { - fn into_py(self, py: Python) -> Py { + impl IntoPy> for $rust_type { + fn into_py(self, py: Python) -> Py { self.to_object(py).into() } } impl<'source> FromPyObject<'source> for $rust_type { - fn extract(ob: &'source PyAny) -> PyResult<$rust_type> { + fn extract(ob: &'source PyObject) -> PyResult<$rust_type> { unsafe { let num = ffi::PyNumber_Index(ob.as_ptr()); if num.is_null() { @@ -110,7 +110,7 @@ macro_rules! int_convert_128 { /// and [extract](struct.PyObject.html#method.extract) /// with the primitive Rust integer types. #[repr(transparent)] -pub struct PyLong(PyAny); +pub struct PyLong(PyObject); pyobject_native_var_type!(PyLong, ffi::PyLong_Type, ffi::PyLong_Check); @@ -118,19 +118,19 @@ macro_rules! int_fits_c_long { ($rust_type:ty) => { impl ToPyObject for $rust_type { #![cfg_attr(feature = "cargo-clippy", allow(clippy::cast_lossless))] - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { unsafe { py.from_owned_ptr(ffi::PyLong_FromLong(*self as c_long)) } } } - impl IntoPy> for $rust_type { + impl IntoPy> for $rust_type { #![cfg_attr(feature = "cargo-clippy", allow(clippy::cast_lossless))] - fn into_py(self, _py: Python) -> Py { + fn into_py(self, _py: Python) -> Py { unsafe { Py::from_owned_ptr_or_panic(ffi::PyLong_FromLong(self as c_long)) } } } impl<'source> FromPyObject<'source> for $rust_type { - fn extract(obj: &'source PyAny) -> PyResult { + fn extract(obj: &'source PyObject) -> PyResult { let ptr = obj.as_ptr(); let val = unsafe { let num = ffi::PyNumber_Index(ptr); @@ -155,18 +155,18 @@ macro_rules! int_convert_u64_or_i64 { ($rust_type:ty, $pylong_from_ll_or_ull:expr, $pylong_as_ll_or_ull:expr) => { impl ToPyObject for $rust_type { #[inline] - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { unsafe { py.from_owned_ptr($pylong_from_ll_or_ull(*self)) } } } - impl IntoPy> for $rust_type { + impl IntoPy> for $rust_type { #[inline] - fn into_py(self, _py: Python) -> Py { + fn into_py(self, _py: Python) -> Py { unsafe { Py::from_owned_ptr_or_panic($pylong_from_ll_or_ull(self)) } } } impl<'source> FromPyObject<'source> for $rust_type { - fn extract(ob: &'source PyAny) -> PyResult<$rust_type> { + fn extract(ob: &'source PyObject) -> PyResult<$rust_type> { let ptr = ob.as_ptr(); unsafe { let num = ffi::PyNumber_Index(ptr); @@ -226,7 +226,7 @@ mod bigint_conversion { use super::*; use num_bigint::{BigInt, BigUint}; - unsafe fn extract_small(ob: &PyAny, n: usize, is_signed: c_int) -> PyResult<[c_uchar; 128]> { + unsafe fn extract_small(ob: &PyObject, n: usize, is_signed: c_int) -> PyResult<[c_uchar; 128]> { let buffer = [0; 128]; let ok = ffi::_PyLong_AsByteArray( ob.as_ptr() as *mut ffi::PyLongObject, @@ -242,7 +242,7 @@ mod bigint_conversion { } } - unsafe fn extract_large(ob: &PyAny, n: usize, is_signed: c_int) -> PyResult> { + unsafe fn extract_large(ob: &PyObject, n: usize, is_signed: c_int) -> PyResult> { let buffer = vec![0; n]; let ok = ffi::_PyLong_AsByteArray( ob.as_ptr() as *mut ffi::PyLongObject, @@ -261,7 +261,7 @@ mod bigint_conversion { macro_rules! bigint_conversion { ($rust_ty: ty, $is_signed: expr, $to_bytes: path, $from_bytes: path) => { impl ToPyObject for $rust_ty { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { unsafe { let bytes = $to_bytes(self); let obj = ffi::_PyLong_FromByteArray( @@ -274,13 +274,13 @@ mod bigint_conversion { } } } - impl IntoPy> for $rust_ty { - fn into_py(self, py: Python) -> Py { + impl IntoPy> for $rust_ty { + fn into_py(self, py: Python) -> Py { self.to_object(py).into() } } impl<'source> FromPyObject<'source> for $rust_ty { - fn extract(ob: &'source PyAny) -> PyResult<$rust_ty> { + fn extract(ob: &'source PyObject) -> PyResult<$rust_ty> { unsafe { let num = ffi::PyNumber_Index(ob.as_ptr()); if num.is_null() { @@ -524,7 +524,7 @@ mod test { #[test] #[cfg(not(Py_LIMITED_API))] fn test_u128_overflow() { - use crate::{exceptions, ffi, ObjectProtocol, PyAny}; + use crate::{exceptions, ffi, ObjectProtocol, PyObject}; use std::os::raw::c_uchar; let gil = Python::acquire_gil(); let py = gil.python(); @@ -536,7 +536,7 @@ mod test { super::IS_LITTLE_ENDIAN, 0, ); - let obj: &PyAny = py.from_owned_ptr(obj); + let obj: &PyObject = py.from_owned_ptr(obj); let err = obj.extract::().unwrap_err(); assert!(err.is_instance::(py)); } diff --git a/src/types/sequence.rs b/src/types/sequence.rs index f98ba8ef914..e988e2bf247 100644 --- a/src/types/sequence.rs +++ b/src/types/sequence.rs @@ -6,13 +6,13 @@ use crate::exceptions; use crate::ffi::{self, Py_ssize_t}; use crate::instance::PyNativeType; use crate::objectprotocol::ObjectProtocol; -use crate::types::{PyAny, PyList, PyTuple}; +use crate::types::{PyList, PyObject, PyTuple}; use crate::AsPyPointer; use crate::{FromPyObject, PyTryFrom, ToBorrowedObject}; /// Represents a reference to a Python object supporting the sequence protocol. #[repr(transparent)] -pub struct PySequence(PyAny); +pub struct PySequence(PyObject); pyobject_native_type_named!(PySequence); pyobject_native_type_extract!(PySequence); @@ -43,11 +43,11 @@ impl PySequence { unsafe { let ptr = self .py() - .from_owned_ptr_or_err::(ffi::PySequence_Concat( + .from_owned_ptr_or_err::(ffi::PySequence_Concat( self.as_ptr(), other.as_ptr(), ))?; - Ok(&*(ptr as *const PyAny as *const PySequence)) + Ok(&*(ptr as *const PyObject as *const PySequence)) } } @@ -60,11 +60,11 @@ impl PySequence { unsafe { let ptr = self .py() - .from_owned_ptr_or_err::(ffi::PySequence_Repeat( + .from_owned_ptr_or_err::(ffi::PySequence_Repeat( self.as_ptr(), count as Py_ssize_t, ))?; - Ok(&*(ptr as *const PyAny as *const PySequence)) + Ok(&*(ptr as *const PyObject as *const PySequence)) } } @@ -103,7 +103,7 @@ impl PySequence { /// /// This is equivalent to the Python expression `self[index]`. #[inline] - pub fn get_item(&self, index: isize) -> PyResult<&PyAny> { + pub fn get_item(&self, index: isize) -> PyResult<&PyObject> { unsafe { self.py() .from_owned_ptr_or_err(ffi::PySequence_GetItem(self.as_ptr(), index as Py_ssize_t)) @@ -114,7 +114,7 @@ impl PySequence { /// /// This is equivalent to the Python expression `self[begin:end]`. #[inline] - pub fn get_slice(&self, begin: isize, end: isize) -> PyResult<&PyAny> { + pub fn get_slice(&self, begin: isize, end: isize) -> PyResult<&PyObject> { unsafe { self.py().from_owned_ptr_or_err(ffi::PySequence_GetSlice( self.as_ptr(), @@ -159,7 +159,7 @@ impl PySequence { /// /// This is equivalent to the Python statement `self[i1:i2] = v`. #[inline] - pub fn set_slice(&self, i1: isize, i2: isize, v: &PyAny) -> PyResult<()> { + pub fn set_slice(&self, i1: isize, i2: isize, v: &PyObject) -> PyResult<()> { unsafe { err::error_on_minusone( self.py(), @@ -266,7 +266,7 @@ macro_rules! array_impls { where T: Copy + Default + FromPyObject<'a>, { - default fn extract(obj: &'a PyAny) -> PyResult { + default fn extract(obj: &'a PyObject) -> PyResult { let mut array = [T::default(); $N]; extract_sequence_into_slice(obj, &mut array)?; Ok(array) @@ -277,7 +277,7 @@ macro_rules! array_impls { where for<'a> T: Copy + Default + FromPyObject<'a> + buffer::Element, { - fn extract(obj: &'source PyAny) -> PyResult { + fn extract(obj: &'source PyObject) -> PyResult { let mut array = [T::default(); $N]; // first try buffer protocol if let Ok(buf) = buffer::PyBuffer::get(obj.py(), obj) { @@ -305,7 +305,7 @@ impl<'a, T> FromPyObject<'a> for Vec where T: FromPyObject<'a>, { - default fn extract(obj: &'a PyAny) -> PyResult { + default fn extract(obj: &'a PyObject) -> PyResult { extract_sequence(obj) } } @@ -314,7 +314,7 @@ impl<'source, T> FromPyObject<'source> for Vec where for<'a> T: FromPyObject<'a> + buffer::Element + Copy, { - fn extract(obj: &'source PyAny) -> PyResult { + fn extract(obj: &'source PyObject) -> PyResult { // first try buffer protocol if let Ok(buf) = buffer::PyBuffer::get(obj.py(), obj) { if buf.dimensions() == 1 { @@ -330,7 +330,7 @@ where } } -fn extract_sequence<'s, T>(obj: &'s PyAny) -> PyResult> +fn extract_sequence<'s, T>(obj: &'s PyObject) -> PyResult> where T: FromPyObject<'s>, { @@ -342,7 +342,7 @@ where Ok(v) } -fn extract_sequence_into_slice<'s, T>(obj: &'s PyAny, slice: &mut [T]) -> PyResult<()> +fn extract_sequence_into_slice<'s, T>(obj: &'s PyObject, slice: &mut [T]) -> PyResult<()> where T: FromPyObject<'s>, { @@ -359,7 +359,7 @@ where } impl<'v> PyTryFrom<'v> for PySequence { - fn try_from>(value: V) -> Result<&'v PySequence, PyDowncastError> { + fn try_from>(value: V) -> Result<&'v PySequence, PyDowncastError> { let value = value.into(); unsafe { if ffi::PySequence_Check(value.as_ptr()) != 0 { @@ -370,12 +370,12 @@ impl<'v> PyTryFrom<'v> for PySequence { } } - fn try_from_exact>(value: V) -> Result<&'v PySequence, PyDowncastError> { + fn try_from_exact>(value: V) -> Result<&'v PySequence, PyDowncastError> { ::try_from(value) } #[inline] - unsafe fn try_from_unchecked>(value: V) -> &'v PySequence { + unsafe fn try_from_unchecked>(value: V) -> &'v PySequence { let ptr = value.into() as *const _ as *const PySequence; &*ptr } @@ -387,9 +387,9 @@ mod test { use crate::types::PySequence; use crate::AsPyPointer; use crate::Python; - use crate::{Py, PyAny, PyTryFrom, ToPyObject}; + use crate::{Py, PyObject, PyTryFrom, ToPyObject}; - fn get_object() -> Py { + fn get_object() -> Py { // Convenience function for getting a single unique object let gil = Python::acquire_gil(); let py = gil.python(); diff --git a/src/types/set.rs b/src/types/set.rs index f9000c93b75..56fd111e8b2 100644 --- a/src/types/set.rs +++ b/src/types/set.rs @@ -3,7 +3,7 @@ use crate::err::{self, PyErr, PyResult}; use crate::{ - ffi, AsPyPointer, FromPy, FromPyObject, IntoPy, Py, PyAny, PyNativeType, Python, + ffi, AsPyPointer, FromPy, FromPyObject, IntoPy, Py, PyNativeType, PyObject, Python, ToBorrowedObject, ToPyObject, }; use std::cmp; @@ -12,11 +12,11 @@ use std::{collections, hash, ptr}; /// Represents a Python `set` #[repr(transparent)] -pub struct PySet(PyAny); +pub struct PySet(PyObject); /// Represents a Python `frozenset` #[repr(transparent)] -pub struct PyFrozenSet(PyAny); +pub struct PyFrozenSet(PyObject); pyobject_native_type!(PySet, ffi::PySetObject, ffi::PySet_Type, ffi::PySet_Check); pyobject_native_type!( @@ -98,7 +98,7 @@ impl PySet { } /// Removes and returns an arbitrary element from the set. - pub fn pop(&self) -> Option<&PyAny> { + pub fn pop(&self) -> Option<&PyObject> { let element = unsafe { self.py() .from_owned_ptr_or_err(ffi::PySet_Pop(self.as_ptr())) @@ -123,13 +123,13 @@ impl PySet { #[cfg(not(Py_LIMITED_API))] pub struct PySetIterator<'py> { - set: &'py super::PyAny, + set: &'py super::PyObject, pos: isize, } #[cfg(not(Py_LIMITED_API))] impl<'py> Iterator for PySetIterator<'py> { - type Item = &'py super::PyAny; + type Item = &'py super::PyObject; #[inline] fn next(&mut self) -> Option { @@ -147,7 +147,7 @@ impl<'py> Iterator for PySetIterator<'py> { #[cfg(not(Py_LIMITED_API))] impl<'a> std::iter::IntoIterator for &'a PySet { - type Item = &'a PyAny; + type Item = &'a PyObject; type IntoIter = PySetIterator<'a>; fn into_iter(self) -> Self::IntoIter { @@ -159,7 +159,7 @@ impl ToPyObject for collections::HashSet where T: hash::Hash + Eq + ToPyObject, { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { let set = PySet::new::(py, &[]).expect("Failed to construct empty set"); { for val in self { @@ -174,7 +174,7 @@ impl ToPyObject for collections::BTreeSet where T: hash::Hash + Eq + ToPyObject, { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { let set = PySet::new::(py, &[]).expect("Failed to construct empty set"); { for val in self { @@ -185,9 +185,9 @@ where } } -impl FromPy> for Py +impl FromPy> for Py where - K: IntoPy> + Eq + hash::Hash, + K: IntoPy> + Eq + hash::Hash, S: hash::BuildHasher + Default, { fn from_py(src: HashSet, py: Python) -> Self { @@ -206,15 +206,15 @@ where K: FromPyObject<'source> + cmp::Eq + hash::Hash, S: hash::BuildHasher + Default, { - fn extract(ob: &'source PyAny) -> PyResult { + fn extract(ob: &'source PyObject) -> PyResult { let set: &PySet = ob.downcast()?; set.iter().map(K::extract).collect() } } -impl FromPy> for Py +impl FromPy> for Py where - K: IntoPy> + cmp::Ord + ToPyObject, + K: IntoPy> + cmp::Ord + ToPyObject, { fn from_py(src: BTreeSet, py: Python) -> Self { let set = PySet::empty(py).expect("Failed to construct empty set"); @@ -231,7 +231,7 @@ impl<'source, K> FromPyObject<'source> for BTreeSet where K: FromPyObject<'source> + cmp::Ord, { - fn extract(ob: &'source PyAny) -> PyResult { + fn extract(ob: &'source PyObject) -> PyResult { let set: &PySet = ob.downcast()?; set.iter().map(K::extract).collect() } @@ -289,7 +289,7 @@ impl PyFrozenSet { #[cfg(not(Py_LIMITED_API))] impl<'a> std::iter::IntoIterator for &'a PyFrozenSet { - type Item = &'a PyAny; + type Item = &'a PyObject; type IntoIter = PySetIterator<'a>; fn into_iter(self) -> Self::IntoIter { @@ -303,7 +303,7 @@ impl<'a> std::iter::IntoIterator for &'a PyFrozenSet { #[cfg(test)] mod test { use super::{PyFrozenSet, PySet}; - use crate::{AsPyRef, IntoPy, ObjectProtocol, Py, PyAny, PyTryFrom, Python, ToPyObject}; + use crate::{AsPyRef, IntoPy, ObjectProtocol, Py, PyObject, PyTryFrom, Python, ToPyObject}; use std::collections::{BTreeSet, HashSet}; use std::iter::FromIterator; @@ -492,8 +492,8 @@ mod test { let bt: BTreeSet = [1, 2, 3, 4, 5].iter().cloned().collect(); let hs: HashSet = [1, 2, 3, 4, 5].iter().cloned().collect(); - let bto: Py = bt.clone().into_py(py); - let hso: Py = hs.clone().into_py(py); + let bto: Py = bt.clone().into_py(py); + let hso: Py = hs.clone().into_py(py); assert_eq!(bt, bto.as_ref(py).extract().unwrap()); assert_eq!(hs, hso.as_ref(py).extract().unwrap()); diff --git a/src/types/slice.rs b/src/types/slice.rs index 5d73b7d249f..ea708dc7201 100644 --- a/src/types/slice.rs +++ b/src/types/slice.rs @@ -4,14 +4,14 @@ use crate::err::{PyErr, PyResult}; use crate::ffi::{self, Py_ssize_t}; use crate::instance::PyNativeType; use crate::Python; -use crate::{AsPyPointer, PyAny, ToPyObject}; +use crate::{AsPyPointer, PyObject, ToPyObject}; use std::os::raw::c_long; /// Represents a Python `slice`. /// /// Only `c_long` indices supported at the moment by the `PySlice` object. #[repr(transparent)] -pub struct PySlice(PyAny); +pub struct PySlice(PyObject); pyobject_native_type!( PySlice, @@ -86,7 +86,7 @@ impl PySlice { } impl ToPyObject for PySliceIndices { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { PySlice::new(py, self.start, self.stop, self.step).into() } } diff --git a/src/types/string.rs b/src/types/string.rs index 2f35d7ba5ba..83ceeef4f89 100644 --- a/src/types/string.rs +++ b/src/types/string.rs @@ -1,8 +1,8 @@ // Copyright (c) 2017-present PyO3 Project and Contributors use crate::{ - ffi, gil, AsPyPointer, FromPy, FromPyObject, IntoPy, Py, PyAny, PyErr, PyNativeType, PyResult, - PyTryFrom, Python, ToPyObject, + ffi, gil, AsPyPointer, FromPy, FromPyObject, IntoPy, Py, PyErr, PyNativeType, PyObject, + PyResult, PyTryFrom, Python, ToPyObject, }; use std::borrow::Cow; use std::ffi::CStr; @@ -14,7 +14,7 @@ use std::str; /// /// This type is immutable. #[repr(transparent)] -pub struct PyString(PyAny); +pub struct PyString(PyObject); pyobject_native_var_type!(PyString, ffi::PyUnicode_Type, ffi::PyUnicode_Check); @@ -28,7 +28,11 @@ impl PyString { unsafe { py.from_owned_ptr(ffi::PyUnicode_FromStringAndSize(ptr, len)) } } - pub fn from_object<'p>(src: &'p PyAny, encoding: &str, errors: &str) -> PyResult<&'p PyString> { + pub fn from_object<'p>( + src: &'p PyObject, + encoding: &str, + errors: &str, + ) -> PyResult<&'p PyString> { unsafe { src.py() .from_owned_ptr_or_err::(ffi::PyUnicode_FromEncodedObject( @@ -98,14 +102,14 @@ impl PyString { /// See `PyString::new` for details on the conversion. impl ToPyObject for str { #[inline] - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { PyString::new(py, self).into() } } -impl<'a> IntoPy> for &'a str { +impl<'a> IntoPy> for &'a str { #[inline] - fn into_py(self, py: Python) -> Py { + fn into_py(self, py: Python) -> Py { PyString::new(py, self).into_py(py) } } @@ -114,7 +118,7 @@ impl<'a> IntoPy> for &'a str { /// See `PyString::new` for details on the conversion. impl<'a> ToPyObject for Cow<'a, str> { #[inline] - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { PyString::new(py, self).into() } } @@ -123,20 +127,20 @@ impl<'a> ToPyObject for Cow<'a, str> { /// See `PyString::new` for details on the conversion. impl ToPyObject for String { #[inline] - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { PyString::new(py, self).into() } } -impl FromPy for Py { +impl FromPy for Py { fn from_py(other: String, py: Python) -> Self { PyString::new(py, &other).into_py(py) } } -impl<'a> IntoPy> for &'a String { +impl<'a> IntoPy> for &'a String { #[inline] - fn into_py(self, py: Python) -> Py { + fn into_py(self, py: Python) -> Py { PyString::new(py, self).into_py(py) } } @@ -144,7 +148,7 @@ impl<'a> IntoPy> for &'a String { /// Allows extracting strings from Python objects. /// Accepts Python `str` and `unicode` objects. impl<'source> crate::FromPyObject<'source> for Cow<'source, str> { - fn extract(ob: &'source PyAny) -> PyResult { + fn extract(ob: &'source PyObject) -> PyResult { ::try_from(ob)?.to_string() } } @@ -152,7 +156,7 @@ impl<'source> crate::FromPyObject<'source> for Cow<'source, str> { /// Allows extracting strings from Python objects. /// Accepts Python `str` and `unicode` objects. impl<'a> crate::FromPyObject<'a> for &'a str { - fn extract(ob: &'a PyAny) -> PyResult { + fn extract(ob: &'a PyObject) -> PyResult { let s: Cow<'a, str> = crate::FromPyObject::extract(ob)?; match s { Cow::Borrowed(r) => Ok(r), @@ -167,7 +171,7 @@ impl<'a> crate::FromPyObject<'a> for &'a str { /// Allows extracting strings from Python objects. /// Accepts Python `str` and `unicode` objects. impl<'source> FromPyObject<'source> for String { - fn extract(obj: &'source PyAny) -> PyResult { + fn extract(obj: &'source PyObject) -> PyResult { ::try_from(obj)? .to_string() .map(Cow::into_owned) diff --git a/src/types/tuple.rs b/src/types/tuple.rs index 71ebd8643a1..0b92240b073 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -3,7 +3,7 @@ use crate::ffi::{self, Py_ssize_t}; use crate::{ exceptions, AsPyPointer, FromPy, FromPyObject, IntoPy, IntoPyPointer, ObjectProtocol, Py, - PyAny, PyErr, PyNativeType, PyResult, PyTryFrom, Python, ToPyObject, + PyErr, PyNativeType, PyObject, PyResult, PyTryFrom, Python, ToPyObject, }; use std::slice; @@ -11,7 +11,7 @@ use std::slice; /// /// This type is immutable. #[repr(transparent)] -pub struct PyTuple(PyAny); +pub struct PyTuple(PyObject); pyobject_native_var_type!(PyTuple, ffi::PyTuple_Type, ffi::PyTuple_Check); @@ -71,7 +71,7 @@ impl PyTuple { /// Gets the tuple item at the specified index. /// /// Panics if the index is out of range. - pub fn get_item(&self, index: usize) -> &PyAny { + pub fn get_item(&self, index: usize) -> &PyObject { // TODO: reconsider whether we should panic // It's quite inconsistent that this method takes `Python` when `len()` does not. assert!(index < self.len()); @@ -82,14 +82,14 @@ impl PyTuple { } /// Returns `self` as a slice of objects. - pub fn as_slice(&self) -> &[PyAny] { + pub fn as_slice(&self) -> &[PyObject] { // This is safe because PyObject has the same memory layout as *mut ffi::PyObject, // and because tuples are immutable. // (We don't even need a Python token, thanks to immutability) unsafe { let ptr = self.as_ptr() as *mut ffi::PyTupleObject; let slice = slice::from_raw_parts((*ptr).ob_item.as_ptr(), self.len()); - &*(slice as *const [*mut ffi::PyObject] as *const [PyAny]) + &*(slice as *const [*mut ffi::PyObject] as *const [PyObject]) } } @@ -104,15 +104,15 @@ impl PyTuple { /// Used by `PyTuple::iter()`. pub struct PyTupleIterator<'a> { - slice: &'a [PyAny], + slice: &'a [PyObject], index: usize, } impl<'a> Iterator for PyTupleIterator<'a> { - type Item = &'a PyAny; + type Item = &'a PyObject; #[inline] - fn next(&mut self) -> Option<&'a PyAny> { + fn next(&mut self) -> Option<&'a PyObject> { if self.index < self.slice.len() { let item = &self.slice[self.index]; self.index += 1; @@ -124,7 +124,7 @@ impl<'a> Iterator for PyTupleIterator<'a> { } impl<'a> IntoIterator for &'a PyTuple { - type Item = &'a PyAny; + type Item = &'a PyObject; type IntoIter = PyTupleIterator<'a>; fn into_iter(self) -> Self::IntoIter { @@ -149,7 +149,7 @@ fn wrong_tuple_length(t: &PyTuple, expected_length: usize) -> PyErr { macro_rules! tuple_conversion ({$length:expr,$(($refN:ident, $n:tt, $T:ident)),+} => { impl <$($T: ToPyObject),+> ToPyObject for ($($T,)+) { - fn to_object<'p>(&self, py: Python<'p>) -> &'p PyAny { + fn to_object<'p>(&self, py: Python<'p>) -> &'p PyObject { unsafe { let ptr = ffi::PyTuple_New($length); $(ffi::PyTuple_SetItem(ptr, $n, self.$n.to_object(py).into_ptr());)+ @@ -157,8 +157,8 @@ macro_rules! tuple_conversion ({$length:expr,$(($refN:ident, $n:tt, $T:ident)),+ } } } - impl <$($T: IntoPy>),+> IntoPy> for ($($T,)+) { - fn into_py(self, py: Python) -> Py { + impl <$($T: IntoPy>),+> IntoPy> for ($($T,)+) { + fn into_py(self, py: Python) -> Py { unsafe { let ptr = ffi::PyTuple_New($length); $(ffi::PyTuple_SetItem(ptr, $n, self.$n.into_py(py).into_ptr());)+ @@ -167,7 +167,7 @@ macro_rules! tuple_conversion ({$length:expr,$(($refN:ident, $n:tt, $T:ident)),+ } } - impl <$($T: IntoPy>),+> IntoPy> for ($($T,)+) { + impl <$($T: IntoPy>),+> IntoPy> for ($($T,)+) { fn into_py(self, py: Python) -> Py { unsafe { let ptr = ffi::PyTuple_New($length); @@ -178,7 +178,7 @@ macro_rules! tuple_conversion ({$length:expr,$(($refN:ident, $n:tt, $T:ident)),+ } impl<'s, $($T: FromPyObject<'s>),+> FromPyObject<'s> for ($($T,)+) { - fn extract(obj: &'s PyAny) -> PyResult + fn extract(obj: &'s PyObject) -> PyResult { let t = ::try_from(obj)?; let slice = t.as_slice(); @@ -250,7 +250,7 @@ tuple_conversion!( #[cfg(test)] mod test { - use crate::types::{PyAny, PyTuple}; + use crate::types::{PyObject, PyTuple}; use crate::{ObjectProtocol, PyTryFrom, Python, ToPyObject}; use std::collections::HashSet; @@ -260,7 +260,7 @@ mod test { let py = gil.python(); let ob = PyTuple::new(py, &[1, 2, 3]); assert_eq!(3, ob.len()); - let ob: &PyAny = ob.into(); + let ob: &PyObject = ob.into(); assert_eq!((1, 2, 3), ob.extract().unwrap()); let mut map = HashSet::new(); @@ -276,7 +276,7 @@ mod test { let ob = (1, 2, 3).to_object(py); let tuple = ::try_from(ob).unwrap(); assert_eq!(3, tuple.len()); - let ob: &PyAny = tuple.into(); + let ob: &PyObject = tuple.into(); assert_eq!((1, 2, 3), ob.extract().unwrap()); } diff --git a/src/types/typeobject.rs b/src/types/typeobject.rs index 9d231ed20d9..47a67bdf9ea 100644 --- a/src/types/typeobject.rs +++ b/src/types/typeobject.rs @@ -6,7 +6,7 @@ use crate::err::{PyErr, PyResult}; use crate::ffi; use crate::instance::{Py, PyNativeType}; use crate::type_object::PyTypeObject; -use crate::types::PyAny; +use crate::types::PyObject; use crate::AsPyPointer; use crate::Python; use std::borrow::Cow; @@ -14,7 +14,7 @@ use std::ffi::CStr; /// Represents a reference to a Python `type object`. #[repr(transparent)] -pub struct PyType(PyAny); +pub struct PyType(PyObject); pyobject_native_var_type!(PyType, ffi::PyType_Type, ffi::PyType_Check); diff --git a/tests/test_arithmetics.rs b/tests/test_arithmetics.rs index d92d383af75..eec9c4026cb 100644 --- a/tests/test_arithmetics.rs +++ b/tests/test_arithmetics.rs @@ -153,39 +153,39 @@ fn inplace_operations() { #[pyproto] impl PyNumberProtocol for BinaryArithmetic { - fn __add__(lhs: &PyAny, rhs: &PyAny) -> PyResult { + fn __add__(lhs: &PyObject, rhs: &PyObject) -> PyResult { Ok(format!("{:?} + {:?}", lhs, rhs)) } - fn __sub__(lhs: &PyAny, rhs: &PyAny) -> PyResult { + fn __sub__(lhs: &PyObject, rhs: &PyObject) -> PyResult { Ok(format!("{:?} - {:?}", lhs, rhs)) } - fn __mul__(lhs: &PyAny, rhs: &PyAny) -> PyResult { + fn __mul__(lhs: &PyObject, rhs: &PyObject) -> PyResult { Ok(format!("{:?} * {:?}", lhs, rhs)) } - fn __lshift__(lhs: &PyAny, rhs: &PyAny) -> PyResult { + fn __lshift__(lhs: &PyObject, rhs: &PyObject) -> PyResult { Ok(format!("{:?} << {:?}", lhs, rhs)) } - fn __rshift__(lhs: &PyAny, rhs: &PyAny) -> PyResult { + fn __rshift__(lhs: &PyObject, rhs: &PyObject) -> PyResult { Ok(format!("{:?} >> {:?}", lhs, rhs)) } - fn __and__(lhs: &PyAny, rhs: &PyAny) -> PyResult { + fn __and__(lhs: &PyObject, rhs: &PyObject) -> PyResult { Ok(format!("{:?} & {:?}", lhs, rhs)) } - fn __xor__(lhs: &PyAny, rhs: &PyAny) -> PyResult { + fn __xor__(lhs: &PyObject, rhs: &PyObject) -> PyResult { Ok(format!("{:?} ^ {:?}", lhs, rhs)) } - fn __or__(lhs: &PyAny, rhs: &PyAny) -> PyResult { + fn __or__(lhs: &PyObject, rhs: &PyObject) -> PyResult { Ok(format!("{:?} | {:?}", lhs, rhs)) } - fn __pow__(lhs: &PyAny, rhs: &PyAny, mod_: Option) -> PyResult { + fn __pow__(lhs: &PyObject, rhs: &PyObject, mod_: Option) -> PyResult { Ok(format!("{:?} ** {:?} (mod: {:?})", lhs, rhs, mod_)) } } @@ -226,39 +226,39 @@ struct RhsArithmetic {} #[pyproto] impl PyNumberProtocol for RhsArithmetic { - fn __radd__(&self, other: &PyAny) -> PyResult { + fn __radd__(&self, other: &PyObject) -> PyResult { Ok(format!("{:?} + RA", other)) } - fn __rsub__(&self, other: &PyAny) -> PyResult { + fn __rsub__(&self, other: &PyObject) -> PyResult { Ok(format!("{:?} - RA", other)) } - fn __rmul__(&self, other: &PyAny) -> PyResult { + fn __rmul__(&self, other: &PyObject) -> PyResult { Ok(format!("{:?} * RA", other)) } - fn __rlshift__(&self, other: &PyAny) -> PyResult { + fn __rlshift__(&self, other: &PyObject) -> PyResult { Ok(format!("{:?} << RA", other)) } - fn __rrshift__(&self, other: &PyAny) -> PyResult { + fn __rrshift__(&self, other: &PyObject) -> PyResult { Ok(format!("{:?} >> RA", other)) } - fn __rand__(&self, other: &PyAny) -> PyResult { + fn __rand__(&self, other: &PyObject) -> PyResult { Ok(format!("{:?} & RA", other)) } - fn __rxor__(&self, other: &PyAny) -> PyResult { + fn __rxor__(&self, other: &PyObject) -> PyResult { Ok(format!("{:?} ^ RA", other)) } - fn __ror__(&self, other: &PyAny) -> PyResult { + fn __ror__(&self, other: &PyObject) -> PyResult { Ok(format!("{:?} | RA", other)) } - fn __rpow__(&self, other: &PyAny, _mod: Option<&'p PyAny>) -> PyResult { + fn __rpow__(&self, other: &PyObject, _mod: Option<&'p PyObject>) -> PyResult { Ok(format!("{:?} ** RA", other)) } } @@ -294,27 +294,27 @@ struct LhsAndRhsArithmetic {} #[pyproto] impl PyNumberProtocol for LhsAndRhsArithmetic { - fn __radd__(&self, other: &PyAny) -> PyResult { + fn __radd__(&self, other: &PyObject) -> PyResult { Ok(format!("{:?} + RA", other)) } - fn __rsub__(&self, other: &PyAny) -> PyResult { + fn __rsub__(&self, other: &PyObject) -> PyResult { Ok(format!("{:?} - RA", other)) } - fn __rpow__(&self, other: &PyAny, _mod: Option<&'p PyAny>) -> PyResult { + fn __rpow__(&self, other: &PyObject, _mod: Option<&'p PyObject>) -> PyResult { Ok(format!("{:?} ** RA", other)) } - fn __add__(lhs: &PyAny, rhs: &PyAny) -> PyResult { + fn __add__(lhs: &PyObject, rhs: &PyObject) -> PyResult { Ok(format!("{:?} + {:?}", lhs, rhs)) } - fn __sub__(lhs: &PyAny, rhs: &PyAny) -> PyResult { + fn __sub__(lhs: &PyObject, rhs: &PyObject) -> PyResult { Ok(format!("{:?} - {:?}", lhs, rhs)) } - fn __pow__(lhs: &PyAny, rhs: &PyAny, _mod: Option) -> PyResult { + fn __pow__(lhs: &PyObject, rhs: &PyObject, _mod: Option) -> PyResult { Ok(format!("{:?} ** {:?}", lhs, rhs)) } } @@ -351,7 +351,7 @@ impl PyObjectProtocol for RichComparisons { Ok("RC") } - fn __richcmp__(&self, other: &PyAny, op: CompareOp) -> PyResult { + fn __richcmp__(&self, other: &PyObject, op: CompareOp) -> PyResult { match op { CompareOp::Lt => Ok(format!("{} < {:?}", self.__repr__().unwrap(), other)), CompareOp::Le => Ok(format!("{} <= {:?}", self.__repr__().unwrap(), other)), @@ -372,7 +372,7 @@ impl PyObjectProtocol for RichComparisons2 { Ok("RC2") } - fn __richcmp__(&self, _other: &PyAny, op: CompareOp) -> PyResult> { + fn __richcmp__(&self, _other: &PyObject, op: CompareOp) -> PyResult> { let gil = GILGuard::acquire(); match op { CompareOp::Eq => Ok(true.to_object(gil.python())), diff --git a/tests/test_buffer_protocol.rs b/tests/test_buffer_protocol.rs index 427e5bef266..93171ed7ba7 100644 --- a/tests/test_buffer_protocol.rs +++ b/tests/test_buffer_protocol.rs @@ -108,7 +108,7 @@ fn test_buffer_referenced() { let input = vec![b' ', b'2', b'3']; let gil = Python::acquire_gil(); let py = gil.python(); - let instance: Py = TestBufferClass { + let instance: Py = TestBufferClass { vec: input.clone(), drop_called: drop_called.clone(), } diff --git a/tests/test_class_basics.rs b/tests/test_class_basics.rs index 41e5def2250..059eaaee561 100644 --- a/tests/test_class_basics.rs +++ b/tests/test_class_basics.rs @@ -144,13 +144,13 @@ struct ClassWithObjectField { // PyObject has special case for derive_utils::GetPropertyValue, // so this test is making sure it compiles! #[pyo3(get, set)] - value: Py, + value: Py, } #[pymethods] impl ClassWithObjectField { #[new] - fn new(value: Py) -> ClassWithObjectField { + fn new(value: Py) -> ClassWithObjectField { Self { value } } } diff --git a/tests/test_datetime.rs b/tests/test_datetime.rs index bb62401e8dc..a43e3d3e7f6 100644 --- a/tests/test_datetime.rs +++ b/tests/test_datetime.rs @@ -2,14 +2,14 @@ use pyo3::ffi::*; use pyo3::prelude::*; -use pyo3::types::IntoPyDict; +use pyo3::types::{IntoPyDict, PyObject}; #[allow(clippy::trivially_copy_pass_by_ref)] fn _get_subclasses<'p>( py: &'p Python, py_type: &str, args: &str, -) -> PyResult<(&'p PyAny, &'p PyAny, &'p PyAny)> { +) -> PyResult<(&'p PyObject, &'p PyObject, &'p PyObject)> { // Import the class from Python and create some subclasses let datetime = py.import("datetime")?; diff --git a/tests/test_dunder.rs b/tests/test_dunder.rs index 058dc27a982..0f131e1507a 100644 --- a/tests/test_dunder.rs +++ b/tests/test_dunder.rs @@ -376,8 +376,8 @@ impl<'p> PyContextProtocol<'p> for ContextManager { fn __exit__( &mut self, ty: Option<&'p PyType>, - _value: Option<&'p PyAny>, - _traceback: Option<&'p PyAny>, + _value: Option<&'p PyObject>, + _traceback: Option<&'p PyObject>, ) -> PyResult { let gil = GILGuard::acquire(); self.exit_called = true; @@ -435,7 +435,7 @@ struct Test {} #[pyproto] impl<'p> PyMappingProtocol<'p> for Test { - fn __getitem__(&self, idx: &PyAny) -> PyResult> { + fn __getitem__(&self, idx: &PyObject) -> PyResult> { let gil = GILGuard::acquire(); if let Ok(slice) = idx.cast_as::() { let indices = slice.indices(1000)?; diff --git a/tests/test_gc.rs b/tests/test_gc.rs index 43eae8fff70..be2f8ef6f4d 100644 --- a/tests/test_gc.rs +++ b/tests/test_gc.rs @@ -84,7 +84,7 @@ fn data_is_dropped() { #[allow(dead_code)] #[pyclass] struct GCIntegration { - self_ref: RefCell>, + self_ref: RefCell>, dropped: TestDropCall, } diff --git a/tests/test_inheritance.rs b/tests/test_inheritance.rs index 1ec72302a49..3682dedec67 100644 --- a/tests/test_inheritance.rs +++ b/tests/test_inheritance.rs @@ -39,7 +39,7 @@ impl BaseClass { fn base_method(&self, x: usize) -> usize { x * self.val1 } - fn base_set(&mut self, fn_: &pyo3::PyAny) -> PyResult<()> { + fn base_set(&mut self, fn_: &pyo3::PyObject) -> PyResult<()> { let value: usize = fn_.call0()?.extract()?; self.val1 = value; Ok(()) diff --git a/tests/test_mapping.rs b/tests/test_mapping.rs index 035b96082d9..1f42a13b799 100644 --- a/tests/test_mapping.rs +++ b/tests/test_mapping.rs @@ -58,7 +58,7 @@ impl PyMappingProtocol for Mapping { } /// not an actual reversed implementation, just to demonstrate that the method is callable. - fn __reversed__(&self) -> PyResult> { + fn __reversed__(&self) -> PyResult> { let gil = Python::acquire_gil(); Ok(self .index diff --git a/tests/test_methods.rs b/tests/test_methods.rs index b9e9ddab387..ee3af031148 100644 --- a/tests/test_methods.rs +++ b/tests/test_methods.rs @@ -216,7 +216,7 @@ impl MethArgs { py: Python<'p>, args: &PyTuple, kwargs: Option<&PyDict>, - ) -> PyResult<&'p PyAny> { + ) -> PyResult<&'p PyObject> { Ok([args.into(), kwargs.to_object(py)].to_object(py)) } @@ -227,7 +227,7 @@ impl MethArgs { a: i32, args: &PyTuple, kwargs: Option<&PyDict>, - ) -> &'p PyAny { + ) -> &'p PyObject { [a.to_object(py), args.into(), kwargs.to_object(py)].to_object(py) } @@ -242,7 +242,7 @@ impl MethArgs { } #[args(kwargs = "**")] - fn get_pos_kw<'p>(&self, py: Python<'p>, a: i32, kwargs: Option<&PyDict>) -> &'p PyAny { + fn get_pos_kw<'p>(&self, py: Python<'p>, a: i32, kwargs: Option<&PyDict>) -> &'p PyObject { [a.to_object(py), kwargs.to_object(py)].to_object(py) } // "args" can be anything that can be extracted from PyTuple diff --git a/tests/test_module.rs b/tests/test_module.rs index 63f9e957b64..8b5a486ea89 100644 --- a/tests/test_module.rs +++ b/tests/test_module.rs @@ -257,14 +257,14 @@ fn test_module_nesting() { // Test that argument parsing specification works for pyfunctions #[pyfunction(a = 5, vararg = "*")] -fn ext_vararg_fn<'p>(py: Python<'p>, a: i32, vararg: &PyTuple) -> &'p PyAny { +fn ext_vararg_fn<'p>(py: Python<'p>, a: i32, vararg: &PyTuple) -> &'p PyObject { [a.to_object(py), vararg.into()].to_object(py) } #[pymodule] fn vararg_module(_py: Python, m: &PyModule) -> PyResult<()> { #[pyfn(m, "int_vararg_fn", a = 5, vararg = "*")] - fn int_vararg_fn<'p>(py: Python<'p>, a: i32, vararg: &PyTuple) -> &'p PyAny { + fn int_vararg_fn<'p>(py: Python<'p>, a: i32, vararg: &PyTuple) -> &'p PyObject { ext_vararg_fn(py, a, vararg) } diff --git a/tests/test_pyself.rs b/tests/test_pyself.rs index bca11933d45..0b766a1daea 100644 --- a/tests/test_pyself.rs +++ b/tests/test_pyself.rs @@ -54,12 +54,12 @@ struct Iter { #[pyproto] impl PyIterProtocol for Iter { - fn __iter__(slf: PyRef) -> PyResult> { + fn __iter__(slf: PyRef) -> PyResult> { let py = unsafe { Python::assume_gil_acquired() }; Ok(slf.into_py(py)) } - fn __next__(mut slf: PyRefMut) -> PyResult>> { + fn __next__(mut slf: PyRefMut) -> PyResult>> { let py = unsafe { Python::assume_gil_acquired() }; let bytes = slf.keys.as_ref(py).as_bytes(); match bytes.get(slf.idx) { @@ -89,7 +89,7 @@ fn reader() -> Reader { fn test_nested_iter() { let gil = Python::acquire_gil(); let py = gil.python(); - let reader: Py = reader().into_py(py); + let reader: Py = reader().into_py(py); py_assert!( py, reader, @@ -101,7 +101,7 @@ fn test_nested_iter() { fn test_clone_ref() { let gil = Python::acquire_gil(); let py = gil.python(); - let reader: Py = reader().into_py(py); + let reader: Py = reader().into_py(py); py_assert!(py, reader, "reader == reader.clone_ref()"); py_assert!(py, reader, "reader == reader.clone_ref_with_py()"); } diff --git a/tests/test_sequence.rs b/tests/test_sequence.rs index c0a21c94f70..49580ff90d0 100644 --- a/tests/test_sequence.rs +++ b/tests/test_sequence.rs @@ -55,7 +55,7 @@ impl PySequenceProtocol for ByteSequence { } } - fn __contains__(&self, other: &PyAny) -> PyResult { + fn __contains__(&self, other: &PyObject) -> PyResult { match u8::extract(other) { Ok(ref x) => Ok(self.elements.contains(x)), Err(_) => Ok(false), diff --git a/tests/test_various.rs b/tests/test_various.rs index 637637e5af7..105dd0fcda6 100644 --- a/tests/test_various.rs +++ b/tests/test_various.rs @@ -130,7 +130,7 @@ impl PickleSupport { pub fn __reduce__<'py>( slf: &'py PyCell, py: Python<'py>, - ) -> PyResult<(&'py PyAny, &'py PyTuple, &'py PyAny)> { + ) -> PyResult<(&'py PyObject, &'py PyTuple, &'py PyObject)> { let cls = slf.to_object(py).getattr("__class__")?; let dict = slf.to_object(py).getattr("__dict__")?; Ok((cls, PyTuple::empty(py), dict))