Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Nov 1, 2024
1 parent fe27f7f commit 67e5724
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
4 changes: 2 additions & 2 deletions include/pybind11/numpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ struct npy_format_descriptor<T, enable_if_t<is_same_ignoring_cvref<T, PyObject *
};

template <>
struct npy_format_descriptor<handle, enable_if_t<sizeof(handle) == sizeof(PyObject*)>> {
struct npy_format_descriptor<handle, enable_if_t<sizeof(handle) == sizeof(PyObject *)>> {
static constexpr auto name = const_name("object");

static constexpr int value = npy_api::NPY_OBJECT_;
Expand All @@ -1446,7 +1446,7 @@ struct npy_format_descriptor<handle, enable_if_t<sizeof(handle) == sizeof(PyObje
};

template <>
struct npy_format_descriptor<object, enable_if_t<sizeof(object) == sizeof(PyObject*)>> {
struct npy_format_descriptor<object, enable_if_t<sizeof(object) == sizeof(PyObject *)>> {
static constexpr auto name = const_name("object");

static constexpr int value = npy_api::NPY_OBJECT_;
Expand Down
30 changes: 14 additions & 16 deletions tests/test_numpy_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,23 +528,21 @@ TEST_SUBMODULE(numpy_array, sm) {
return sum_str_values;
});

sm.def("pass_array_handle_return_sum_str_values",
[](const py::array_t<py::handle> &objs) {
std::string sum_str_values;
for (const auto &obj : objs) {
sum_str_values += py::str(obj.attr("value"));
}
return sum_str_values;
});
sm.def("pass_array_handle_return_sum_str_values", [](const py::array_t<py::handle> &objs) {
std::string sum_str_values;
for (const auto &obj : objs) {
sum_str_values += py::str(obj.attr("value"));
}
return sum_str_values;
});

sm.def("pass_array_object_return_sum_str_values",
[](const py::array_t<py::object> &objs) {
std::string sum_str_values;
for (const auto &obj : objs) {
sum_str_values += py::str(obj.attr("value"));
}
return sum_str_values;
});
sm.def("pass_array_object_return_sum_str_values", [](const py::array_t<py::object> &objs) {
std::string sum_str_values;
for (const auto &obj : objs) {
sum_str_values += py::str(obj.attr("value"));
}
return sum_str_values;
});

sm.def("pass_array_pyobject_ptr_return_as_list",
[](const py::array_t<PyObject *> &objs) -> py::list { return objs; });
Expand Down
17 changes: 5 additions & 12 deletions tests/test_numpy_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,11 @@ def test_round_trip_float():
# other ref-count bugs.
class PyValueHolder:
counter = 0

def __init__(self, value):
self.value = value
PyValueHolder.counter += 1

def __del__(self):
PyValueHolder.counter -= 1

Expand All @@ -646,9 +648,7 @@ def test_pass_array_object_return_sum_str_values_ndarray(func):
for loop in range(100):
# Intentionally all temporaries, do not change.
assert (
func(
np.array(WrapWithPyValueHolder(-3, "four", 5.0), dtype=object)
)
func(np.array(WrapWithPyValueHolder(-3, "four", 5.0), dtype=object))
== "-3four5.0"
)
assert PyValueHolder.counter == initial_counter

Check failure on line 654 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 graalpy-24.1 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_sum_str_values_ndarray[pass_array_pyobject_ptr_return_sum_str_values] AssertionError

Check failure on line 654 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 graalpy-24.1 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_sum_str_values_ndarray[pass_array_handle_return_sum_str_values] AssertionError

Check failure on line 654 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 graalpy-24.1 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_sum_str_values_ndarray[pass_array_object_return_sum_str_values] AssertionError

Check failure on line 654 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.8 β€’ ubuntu-20.04 β€’ x64 -DPYBIND11_FINDPYTHON=ON

test_pass_array_object_return_sum_str_values_ndarray[pass_array_pyobject_ptr_return_sum_str_values] assert 300 == 0 + where 300 = PyValueHolder.counter

Check failure on line 654 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.8 β€’ ubuntu-20.04 β€’ x64 -DPYBIND11_FINDPYTHON=ON

test_pass_array_object_return_sum_str_values_ndarray[pass_array_handle_return_sum_str_values] assert 600 == 300 + where 600 = PyValueHolder.counter

Check failure on line 654 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.8 β€’ ubuntu-20.04 β€’ x64 -DPYBIND11_FINDPYTHON=ON

test_pass_array_object_return_sum_str_values_ndarray[pass_array_object_return_sum_str_values] assert 900 == 600 + where 900 = PyValueHolder.counter

Check failure on line 654 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.9 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_sum_str_values_ndarray[pass_array_pyobject_ptr_return_sum_str_values] assert 300 == 0 + where 300 = PyValueHolder.counter

Check failure on line 654 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.9 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_sum_str_values_ndarray[pass_array_handle_return_sum_str_values] assert 600 == 300 + where 600 = PyValueHolder.counter

Check failure on line 654 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.9 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_sum_str_values_ndarray[pass_array_object_return_sum_str_values] assert 900 == 600 + where 900 = PyValueHolder.counter
Expand All @@ -666,12 +666,7 @@ def test_pass_array_object_return_sum_str_values_list(func):
initial_counter = PyValueHolder.counter
for loop in range(100):
# Intentionally all temporaries, do not change.
assert (
func(
WrapWithPyValueHolder(2, "three", -4.0)
)
== "2three-4.0"
)
assert func(WrapWithPyValueHolder(2, "three", -4.0)) == "2three-4.0"
assert PyValueHolder.counter == initial_counter

Check failure on line 670 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 graalpy-24.1 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_sum_str_values_list[pass_array_pyobject_ptr_return_sum_str_values] AssertionError

Check failure on line 670 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 graalpy-24.1 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_sum_str_values_list[pass_array_handle_return_sum_str_values] AssertionError

Check failure on line 670 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 graalpy-24.1 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_sum_str_values_list[pass_array_object_return_sum_str_values] AssertionError

Check failure on line 670 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.8 β€’ ubuntu-20.04 β€’ x64 -DPYBIND11_FINDPYTHON=ON

test_pass_array_object_return_sum_str_values_list[pass_array_pyobject_ptr_return_sum_str_values] assert 1200 == 900 + where 1200 = PyValueHolder.counter

Check failure on line 670 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.8 β€’ ubuntu-20.04 β€’ x64 -DPYBIND11_FINDPYTHON=ON

test_pass_array_object_return_sum_str_values_list[pass_array_handle_return_sum_str_values] assert 1500 == 1200 + where 1500 = PyValueHolder.counter

Check failure on line 670 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.8 β€’ ubuntu-20.04 β€’ x64 -DPYBIND11_FINDPYTHON=ON

test_pass_array_object_return_sum_str_values_list[pass_array_object_return_sum_str_values] assert 1800 == 1500 + where 1800 = PyValueHolder.counter

Check failure on line 670 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.9 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_sum_str_values_list[pass_array_pyobject_ptr_return_sum_str_values] assert 1200 == 900 + where 1200 = PyValueHolder.counter

Check failure on line 670 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.9 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_sum_str_values_list[pass_array_handle_return_sum_str_values] assert 1500 == 1200 + where 1500 = PyValueHolder.counter

Check failure on line 670 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.9 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_sum_str_values_list[pass_array_object_return_sum_str_values] assert 1800 == 1500 + where 1800 = PyValueHolder.counter


Expand All @@ -688,9 +683,7 @@ def test_pass_array_object_return_as_list(func):
for loop in range(100):
# Intentionally all temporaries, do not change.
assert UnwrapPyValueHolder(
func(
np.array(WrapWithPyValueHolder(-1, "two", 3.0), dtype=object)
)
func(np.array(WrapWithPyValueHolder(-1, "two", 3.0), dtype=object))
) == [-1, "two", 3.0]
assert PyValueHolder.counter == initial_counter

Check failure on line 688 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 graalpy-24.1 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_as_list[pass_array_pyobject_ptr_return_as_list] AssertionError

Check failure on line 688 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 graalpy-24.1 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_as_list[pass_array_handle_return_as_list] AssertionError

Check failure on line 688 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 graalpy-24.1 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_as_list[pass_array_object_return_as_list] AssertionError

Check failure on line 688 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.8 β€’ ubuntu-20.04 β€’ x64 -DPYBIND11_FINDPYTHON=ON

test_pass_array_object_return_as_list[pass_array_pyobject_ptr_return_as_list] assert 2100 == 1800 + where 2100 = PyValueHolder.counter

Check failure on line 688 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.8 β€’ ubuntu-20.04 β€’ x64 -DPYBIND11_FINDPYTHON=ON

test_pass_array_object_return_as_list[pass_array_handle_return_as_list] assert 2400 == 2100 + where 2400 = PyValueHolder.counter

Check failure on line 688 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.8 β€’ ubuntu-20.04 β€’ x64 -DPYBIND11_FINDPYTHON=ON

test_pass_array_object_return_as_list[pass_array_object_return_as_list] assert 2700 == 2400 + where 2700 = PyValueHolder.counter

Check failure on line 688 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.9 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_as_list[pass_array_pyobject_ptr_return_as_list] assert 2100 == 1800 + where 2100 = PyValueHolder.counter

Check failure on line 688 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.9 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_as_list[pass_array_handle_return_as_list] assert 2400 == 2100 + where 2400 = PyValueHolder.counter

Check failure on line 688 in tests/test_numpy_array.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.9 β€’ ubuntu-20.04 β€’ x64

test_pass_array_object_return_as_list[pass_array_object_return_as_list] assert 2700 == 2400 + where 2700 = PyValueHolder.counter

Expand Down

0 comments on commit 67e5724

Please sign in to comment.