From ccbe68b084806dece5863437a7dc93de20bd9b15 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Mon, 4 Feb 2019 16:19:36 +0100 Subject: [PATCH] added binding delattr() -> PyObject_DelAttr analogous to hasattr() --- include/pybind11/pytypes.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index fa5ed7cbd..3329fda2d 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -388,6 +388,14 @@ inline bool hasattr(handle obj, const char *name) { return PyObject_HasAttrString(obj.ptr(), name) == 1; } +inline void delattr(handle obj, handle name) { + if (PyObject_DelAttr(obj.ptr(), name.ptr()) != 0) { throw error_already_set(); } +} + +inline void delattr(handle obj, const char *name) { + if (PyObject_DelAttrString(obj.ptr(), name) != 0) { throw error_already_set(); } +} + inline object getattr(handle obj, handle name) { PyObject *result = PyObject_GetAttr(obj.ptr(), name.ptr()); if (!result) { throw error_already_set(); } @@ -459,7 +467,6 @@ object object_or_cast(T &&o); // Match a PyObject*, which we want to convert directly to handle via its converting constructor inline handle object_or_cast(PyObject *ptr) { return ptr; } - template class accessor : public object_api> { using key_type = typename Policy::key_type;