From 18fb3e323a8d0f0cd6d36bf33b26e2bdf3c01451 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Mon, 25 Apr 2016 03:25:34 +0200 Subject: [PATCH] added a pybind11::none class --- include/pybind11/pytypes.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index d8cfa0f85..36e163045 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -212,7 +212,7 @@ private: ssize_t pos = 0; }; -inline bool iterable_check(PyObject *obj) { +inline bool PyIterable_Check(PyObject *obj) { PyObject *iter = PyObject_GetIter(obj); if (iter) { Py_DECREF(iter); @@ -222,8 +222,10 @@ inline bool iterable_check(PyObject *obj) { return false; } } -NAMESPACE_END(detail) + +inline bool PyNone_Check(PyObject *o) { return o == Py_None; } +NAMESPACE_END(detail) #define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, CvtStmt) \ Name(const handle &h, bool borrowed) : Parent(h, borrowed) { CvtStmt; } \ @@ -261,7 +263,7 @@ private: class iterable : public object { public: - PYBIND11_OBJECT_DEFAULT(iterable, object, detail::iterable_check) + PYBIND11_OBJECT_DEFAULT(iterable, object, detail::PyIterable_Check) }; inline detail::accessor handle::operator[](handle key) const { return detail::accessor(ptr(), key.ptr(), false); } @@ -319,6 +321,12 @@ public: } }; +class none : public object { +public: + PYBIND11_OBJECT(none, object, detail::PyNone_Check) + none() : object(Py_None, true) { } +}; + class bool_ : public object { public: PYBIND11_OBJECT_DEFAULT(bool_, object, PyBool_Check)