Skip to content

Commit

Permalink
Update tests for numpy 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Jun 16, 2024
1 parent 5749a08 commit 3f7925f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/4258.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for `bool` conversion with `numpy` 2.0's `numpy.bool` type
1 change: 1 addition & 0 deletions pyo3-macros-backend/src/pyimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
{
Expand Down
3 changes: 2 additions & 1 deletion pytests/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ 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():
Expand Down
2 changes: 1 addition & 1 deletion src/types/boolobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 3f7925f

Please sign in to comment.