mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
Fixing SystemError when nb_bool/nb_nonzero sets a Python exception in type_caster<bool>::load (#1976)
This commit is contained in:
parent
b32b762c60
commit
55ff464233
@ -1172,6 +1172,8 @@ public:
|
||||
if (res == 0 || res == 1) {
|
||||
value = (bool) res;
|
||||
return true;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user