From dc4f114d6772337d8b1568c6dbb0bf35deaa84dd Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 26 Feb 2022 20:10:33 +0100 Subject: [PATCH] Address review comments --- CHANGELOG.md | 2 +- src/impl_/pyclass.rs | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef979445..91b125a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,11 +33,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `wrap_pyfunction!` can now wrap a `#[pyfunction]` which is implemented in a different Rust module or crate. [#2091](https://github.com/PyO3/pyo3/pull/2091) - Add `PyAny::contains` method (`in` operator for `PyAny`). [#2115](https://github.com/PyO3/pyo3/pull/2115) - Add `PyMapping::contains` method (`in` operator for `PyMapping`). [#2133](https://github.com/PyO3/pyo3/pull/2133) -- Add support for the `__getattribute__` magic method. [#2187](https://github.com/PyO3/pyo3/pull/2187) - Add garbage collection magic methods `__traverse__` and `__clear__` to `#[pymethods]`. [#2159](https://github.com/PyO3/pyo3/pull/2159) - Add support for `from_py_with` on struct tuples and enums to override the default from-Python conversion. [#2181](https://github.com/PyO3/pyo3/pull/2181) - Add `eq`, `ne`, `lt`, `le`, `gt`, `ge` methods to `PyAny` that wrap `rich_compare`. [#2175](https://github.com/PyO3/pyo3/pull/2175) - Add `Py::is` and `PyAny::is` methods to check for object identity. [#2183](https://github.com/PyO3/pyo3/pull/2183) +- Add support for the `__getattribute__` magic method. [#2187](https://github.com/PyO3/pyo3/pull/2187) ### Changed diff --git a/src/impl_/pyclass.rs b/src/impl_/pyclass.rs index 3ec2c7ef..d79f7c4e 100644 --- a/src/impl_/pyclass.rs +++ b/src/impl_/pyclass.rs @@ -210,8 +210,11 @@ slot_fragment_trait! { attr: *mut ffi::PyObject, ) -> PyResult<*mut ffi::PyObject> { let res = ffi::PyObject_GenericGetAttr(slf, attr); - if res.is_null() { Err(PyErr::fetch(py)) } - else { Ok(res) } + if res.is_null() { + Err(PyErr::fetch(py)) + } else { + Ok(res) + } } } @@ -225,8 +228,10 @@ slot_fragment_trait! { py: Python, _slf: *mut ffi::PyObject, attr: *mut ffi::PyObject, - ) -> PyResult<*mut ffi::PyObject> { - Err(PyErr::new::((Py::::from_owned_ptr(py, attr),))) + ) -> PyResult<*mut ffi::PyObject> { + Err(PyErr::new::( + (Py::::from_borrowed_ptr(py, attr),) + )) } } @@ -239,7 +244,6 @@ macro_rules! generate_pyclass_getattro_slot { attr: *mut $crate::ffi::PyObject, ) -> *mut $crate::ffi::PyObject { use ::std::result::Result::*; - use $crate::callback::IntoPyCallbackOutput; use $crate::impl_::pyclass::*; let gil = $crate::GILPool::new(); let py = gil.python(); @@ -254,9 +258,9 @@ macro_rules! generate_pyclass_getattro_slot { // - If it fails with AttributeError, try __getattr__. // - If it fails otherwise, reraise. match collector.__getattribute__(py, _slf, attr) { - Ok(obj) => obj.convert(py), + Ok(obj) => Ok(obj), Err(e) if e.is_instance_of::<$crate::exceptions::PyAttributeError>(py) => { - collector.__getattr__(py, _slf, attr).convert(py) + collector.__getattr__(py, _slf, attr) } Err(e) => Err(e), }