Update tests for numpy 2.0 (#4258)

This commit is contained in:
Alex Gaynor 2024-06-16 20:05:55 -04:00 committed by GitHub
parent 79591f2161
commit baae9291cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 2 deletions

View File

@ -0,0 +1 @@
Added support for `bool` conversion with `numpy` 2.0's `numpy.bool` type

View File

@ -219,6 +219,7 @@ fn impl_py_methods(
) -> TokenStream {
let Ctx { pyo3_path } = ctx;
quote! {
#[allow(unknown_lints, non_local_definitions)]
impl #pyo3_path::impl_::pyclass::PyMethods<#ty>
for #pyo3_path::impl_::pyclass::PyClassImplCollector<#ty>
{

View File

@ -54,7 +54,11 @@ def test_import_in_subinterpreter_forbidden():
def test_type_full_name_includes_module():
numpy = pytest.importorskip("numpy")
assert pyo3_pytests.misc.get_type_full_name(numpy.bool_(True)) == "numpy.bool_"
# For numpy 1.x and 2.x
assert pyo3_pytests.misc.get_type_full_name(numpy.bool_(True)) in [
"numpy.bool",
"numpy.bool_",
]
def test_accepts_numpy_bool():

View File

@ -114,7 +114,7 @@ impl FromPyObject<'_> for bool {
if obj
.get_type()
.name()
.map_or(false, |name| name == "numpy.bool_")
.map_or(false, |name| name == "numpy.bool_" || name == "numpy.bool")
{
let missing_conversion = |obj: &Bound<'_, PyAny>| {
PyTypeError::new_err(format!(