Skip to content

Commit baae929

Browse files
authored
Update tests for numpy 2.0 (#4258)
1 parent 79591f2 commit baae929

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

newsfragments/4258.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added support for `bool` conversion with `numpy` 2.0's `numpy.bool` type

pyo3-macros-backend/src/pyimpl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ fn impl_py_methods(
219219
) -> TokenStream {
220220
let Ctx { pyo3_path } = ctx;
221221
quote! {
222+
#[allow(unknown_lints, non_local_definitions)]
222223
impl #pyo3_path::impl_::pyclass::PyMethods<#ty>
223224
for #pyo3_path::impl_::pyclass::PyClassImplCollector<#ty>
224225
{

pytests/tests/test_misc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ def test_import_in_subinterpreter_forbidden():
5454
def test_type_full_name_includes_module():
5555
numpy = pytest.importorskip("numpy")
5656

57-
assert pyo3_pytests.misc.get_type_full_name(numpy.bool_(True)) == "numpy.bool_"
57+
# For numpy 1.x and 2.x
58+
assert pyo3_pytests.misc.get_type_full_name(numpy.bool_(True)) in [
59+
"numpy.bool",
60+
"numpy.bool_",
61+
]
5862

5963

6064
def test_accepts_numpy_bool():

src/types/boolobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl FromPyObject<'_> for bool {
114114
if obj
115115
.get_type()
116116
.name()
117-
.map_or(false, |name| name == "numpy.bool_")
117+
.map_or(false, |name| name == "numpy.bool_" || name == "numpy.bool")
118118
{
119119
let missing_conversion = |obj: &Bound<'_, PyAny>| {
120120
PyTypeError::new_err(format!(

0 commit comments

Comments
 (0)