improved signature names for subclasses of pybind11::handle

This commit is contained in:
Wenzel Jakob 2016-01-17 22:36:38 +01:00
parent d0325bbd97
commit 56e9f4942b
3 changed files with 11 additions and 3 deletions

View File

@ -467,6 +467,9 @@ protected:
holder_type holder; holder_type holder;
}; };
template <typename T> struct handle_type_name { static PYBIND11_DESCR name() { return _<T>(); } };
template <> struct handle_type_name<bytes> { static PYBIND11_DESCR name() { return _(PYBIND11_BYTES_NAME); } };
template <typename type> template <typename type>
struct type_caster<type, typename std::enable_if<std::is_base_of<handle, type>::value>::type> { struct type_caster<type, typename std::enable_if<std::is_base_of<handle, type>::value>::type> {
public: public:
@ -477,10 +480,9 @@ public:
bool load(PyObject *src, bool /* convert */) { value = type(src, true); return value.check(); } bool load(PyObject *src, bool /* convert */) { value = type(src, true); return value.check(); }
static PyObject *cast(const handle &src, return_value_policy /* policy */, PyObject * /* parent */) { static PyObject *cast(const handle &src, return_value_policy /* policy */, PyObject * /* parent */) {
src.inc_ref(); src.inc_ref(); return (PyObject *) src.ptr();
return (PyObject *) src.ptr();
} }
PYBIND11_TYPE_CASTER(type, _<type>()); PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name());
}; };
NAMESPACE_END(detail) NAMESPACE_END(detail)

View File

@ -94,6 +94,7 @@
#define PYBIND11_LONG_CHECK(o) PyLong_Check(o) #define PYBIND11_LONG_CHECK(o) PyLong_Check(o)
#define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o) #define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o)
#define PYBIND11_LONG_AS_UNSIGNED_LONGLONG(o) PyLong_AsUnsignedLongLong(o) #define PYBIND11_LONG_AS_UNSIGNED_LONGLONG(o) PyLong_AsUnsignedLongLong(o)
#define PYBIND11_BYTES_NAME "bytes"
#define PYBIND11_STRING_NAME "str" #define PYBIND11_STRING_NAME "str"
#define PYBIND11_SLICE_OBJECT PyObject #define PYBIND11_SLICE_OBJECT PyObject
#else #else
@ -105,6 +106,7 @@
#define PYBIND11_LONG_CHECK(o) (PyInt_Check(o) || PyLong_Check(o)) #define PYBIND11_LONG_CHECK(o) (PyInt_Check(o) || PyLong_Check(o))
#define PYBIND11_LONG_AS_LONGLONG(o) (PyInt_Check(o) ? (long long) PyLong_AsLong(o) : PyLong_AsLongLong(o)) #define PYBIND11_LONG_AS_LONGLONG(o) (PyInt_Check(o) ? (long long) PyLong_AsLong(o) : PyLong_AsLongLong(o))
#define PYBIND11_LONG_AS_UNSIGNED_LONGLONG(o) (PyInt_Check(o) ? (unsigned long long) PyLong_AsUnsignedLong(o) : PyLong_AsUnsignedLongLong(o)) #define PYBIND11_LONG_AS_UNSIGNED_LONGLONG(o) (PyInt_Check(o) ? (unsigned long long) PyLong_AsUnsignedLong(o) : PyLong_AsUnsignedLongLong(o))
#define PYBIND11_BYTES_NAME "str"
#define PYBIND11_STRING_NAME "unicode" #define PYBIND11_STRING_NAME "unicode"
#define PYBIND11_SLICE_OBJECT PySliceObject #define PYBIND11_SLICE_OBJECT PySliceObject
#endif #endif

View File

@ -150,6 +150,10 @@ DECL_FMT(std::complex<double>, NPY_CDOUBLE);
NAMESPACE_BEGIN(detail) NAMESPACE_BEGIN(detail)
template <typename T> struct handle_type_name<array_t<T>> {
static PYBIND11_DESCR name() { return _("array[") + type_caster<T>::name() + _("]"); }
};
template <typename Func, typename Return, typename... Args> template <typename Func, typename Return, typename... Args>
struct vectorize_helper { struct vectorize_helper {
typename std::remove_reference<Func>::type f; typename std::remove_reference<Func>::type f;