Fixing SystemError when nb_bool/nb_nonzero sets a Python exception in type_caster<bool>::load (#1976)

This commit is contained in:
Yannick Jadoul 2019-11-14 08:55:34 +01:00 committed by Wenzel Jakob
parent b32b762c60
commit 55ff464233
2 changed files with 6 additions and 0 deletions

View File

@ -1172,6 +1172,8 @@ public:
if (res == 0 || res == 1) {
value = (bool) res;
return true;
} else {
PyErr_Clear();
}
}
return false;

View File

@ -318,11 +318,15 @@ def test_numpy_bool():
import numpy as np
convert, noconvert = m.bool_passthrough, m.bool_passthrough_noconvert
def cant_convert(v):
pytest.raises(TypeError, convert, v)
# np.bool_ is not considered implicit
assert convert(np.bool_(True)) is True
assert convert(np.bool_(False)) is False
assert noconvert(np.bool_(True)) is True
assert noconvert(np.bool_(False)) is False
cant_convert(np.zeros(2, dtype='int'))
def test_int_long():