Add `Py::setattr` method
This commit is contained in:
parent
b0d957bc35
commit
91caa814d0
|
@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Update `indoc` optional dependency to 1.0. [#2004](https://github.com/PyO3/pyo3/pull/2004)
|
- Update `indoc` optional dependency to 1.0. [#2004](https://github.com/PyO3/pyo3/pull/2004)
|
||||||
- Update `paste` optional dependency to 1.0. [#2004](https://github.com/PyO3/pyo3/pull/2004)
|
- Update `paste` optional dependency to 1.0. [#2004](https://github.com/PyO3/pyo3/pull/2004)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Add `Py::setattr` method. [#2009](https://github.com/PyO3/pyo3/pull/2009)
|
||||||
|
|
||||||
## [0.15.1] - 2021-11-19
|
## [0.15.1] - 2021-11-19
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -528,6 +528,21 @@ impl<T> Py<T> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets an attribute value.
|
||||||
|
///
|
||||||
|
/// This is equivalent to the Python expression `self.attr_name = value`.
|
||||||
|
pub fn setattr<N, V>(&self, py: Python, attr_name: N, value: V) -> PyResult<()>
|
||||||
|
where
|
||||||
|
N: ToPyObject,
|
||||||
|
V: ToPyObject,
|
||||||
|
{
|
||||||
|
attr_name.with_borrowed_ptr(py, move |attr_name| {
|
||||||
|
value.with_borrowed_ptr(py, |value| unsafe {
|
||||||
|
err::error_on_minusone(py, ffi::PyObject_SetAttr(self.as_ptr(), attr_name, value))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Calls the object.
|
/// Calls the object.
|
||||||
///
|
///
|
||||||
/// This is equivalent to the Python expression `self(*args, **kwargs)`.
|
/// This is equivalent to the Python expression `self(*args, **kwargs)`.
|
||||||
|
|
Loading…
Reference in New Issue