Skip to content

Commit

Permalink
Bool conversion: only special-case np.bool_ in 1st pass
Browse files Browse the repository at this point in the history
  • Loading branch information
aldanor committed Jul 23, 2017
1 parent 9b4f569 commit 31401f8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,11 @@ template <> class type_caster<bool> {
}
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<char>() == 'b') {
value = PyObject_IsTrue(src.ptr()) == 1;
Expand Down

0 comments on commit 31401f8

Please sign in to comment.