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 10, 2017
1 parent d350fd7 commit a919783
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 @@ -1031,8 +1031,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 a919783

Please sign in to comment.