Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
birkenfeld committed Feb 26, 2022
1 parent 0678f11 commit dc4f114
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 11 additions & 7 deletions src/impl_/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand All @@ -225,8 +228,10 @@ slot_fragment_trait! {
py: Python,
_slf: *mut ffi::PyObject,
attr: *mut ffi::PyObject,
) -> PyResult<*mut ffi::PyObject> {
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_owned_ptr(py, attr),)))
) -> PyResult<*mut ffi::PyObject> {
Err(PyErr::new::<PyAttributeError, _>(
(Py::<PyAny>::from_borrowed_ptr(py, attr),)
))
}
}

Expand All @@ -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();
Expand All @@ -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),
}
Expand Down

0 comments on commit dc4f114

Please sign in to comment.