From 31401f816892ca73e163daf19fbdb4b6db0a23b7 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Mon, 10 Jul 2017 17:54:20 +0100 Subject: [PATCH] Bool conversion: only special-case np.bool_ in 1st pass --- include/pybind11/cast.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 41fcec02e5..3535cf9332 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1078,8 +1078,11 @@ template <> class type_caster { } return false; } - if (hasattr(src, "dtype")) { + else if (hasattr(src, "dtype")) { // Allow non-implicit conversion for numpy booleans + // + // Note: this will only run in the first (noconvert) pass; + // during the second pass, it will be handled by __bool__ logic. auto dtype = src.attr("dtype"); if (hasattr(dtype, "kind") && dtype.attr("kind").cast() == 'b') { value = PyObject_IsTrue(src.ptr()) == 1;