From 711847e2995bf0f4868648bae6dd77a99be399ec Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sun, 11 Jul 2021 16:39:52 -0700 Subject: [PATCH] Copying from prework_no_rst branch (PR #3087): test_numpy_array.cpp, test_stl.cpp --- tests/test_numpy_array.cpp | 124 ++++++++++++++----------------------- tests/test_stl.cpp | 14 ++--- 2 files changed, 51 insertions(+), 87 deletions(-) diff --git a/tests/test_numpy_array.cpp b/tests/test_numpy_array.cpp index a6c7ae8d74..5c22a3d25b 100644 --- a/tests/test_numpy_array.cpp +++ b/tests/test_numpy_array.cpp @@ -226,8 +226,7 @@ TEST_SUBMODULE(numpy_array, sm) { return py::isinstance(std::move(yes)) && !py::isinstance(std::move(no)); }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("isinstance_typed", [](py::object o) { + sm.def("isinstance_typed", [](const py::object &o) { return py::isinstance>(o) && !py::isinstance>(o); }); @@ -248,60 +247,47 @@ TEST_SUBMODULE(numpy_array, sm) { }); // test_overload_resolution - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded", [](py::array_t) { return "double"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded", [](py::array_t) { return "float"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded", [](py::array_t) { return "int"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded", [](py::array_t) { return "unsigned short"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded", [](py::array_t) { return "long long"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded", [](py::array_t>) { return "double complex"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded", [](py::array_t>) { return "float complex"; }); - - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded2", [](py::array_t>) { return "double complex"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded2", [](py::array_t) { return "double"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded2", [](py::array_t>) { return "float complex"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded2", [](py::array_t) { return "float"; }); + sm.def("overloaded", [](const py::array_t &) { return "double"; }); + sm.def("overloaded", [](const py::array_t &) { return "float"; }); + sm.def("overloaded", [](const py::array_t &) { return "int"; }); + sm.def("overloaded", [](const py::array_t &) { return "unsigned short"; }); + sm.def("overloaded", [](const py::array_t &) { return "long long"; }); + sm.def("overloaded", + [](const py::array_t> &) { return "double complex"; }); + sm.def("overloaded", [](const py::array_t> &) { return "float complex"; }); + + sm.def("overloaded2", + [](const py::array_t> &) { return "double complex"; }); + sm.def("overloaded2", [](const py::array_t &) { return "double"; }); + sm.def("overloaded2", + [](const py::array_t> &) { return "float complex"; }); + sm.def("overloaded2", [](const py::array_t &) { return "float"; }); // [workaround(intel)] ICC 20/21 breaks with py::arg().stuff, using py::arg{}.stuff works. // Only accept the exact types: - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded3", [](py::array_t) { return "int"; }, py::arg{}.noconvert()); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded3", [](py::array_t) { return "double"; }, py::arg{}.noconvert()); + sm.def( + "overloaded3", [](const py::array_t &) { return "int"; }, py::arg{}.noconvert()); + sm.def( + "overloaded3", + [](const py::array_t &) { return "double"; }, + py::arg{}.noconvert()); // Make sure we don't do unsafe coercion (e.g. float to int) when not using forcecast, but // rather that float gets converted via the safe (conversion to double) overload: - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded4", [](py::array_t) { return "long long"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded4", [](py::array_t) { return "double"; }); + sm.def("overloaded4", [](const py::array_t &) { return "long long"; }); + sm.def("overloaded4", [](const py::array_t &) { return "double"; }); // But we do allow conversion to int if forcecast is enabled (but only if no overload matches // without conversion) - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded5", [](py::array_t) { return "unsigned int"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("overloaded5", [](py::array_t) { return "double"; }); + sm.def("overloaded5", [](const py::array_t &) { return "unsigned int"; }); + sm.def("overloaded5", [](const py::array_t &) { return "double"; }); // test_greedy_string_overload // Issue 685: ndarray shouldn't go to std::string overload - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("issue685", [](std::string) { return "string"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("issue685", [](py::array) { return "array"; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("issue685", [](py::object) { return "other"; }); + sm.def("issue685", [](const std::string &) { return "string"; }); + sm.def("issue685", [](const py::array &) { return "array"; }); + sm.def("issue685", [](const py::object &) { return "other"; }); // test_array_unchecked_fixed_dims sm.def("proxy_add2", [](py::array_t a, double v) { @@ -424,73 +410,53 @@ TEST_SUBMODULE(numpy_array, sm) { // test_argument_conversions sm.def( - "accept_double", - // NOLINTNEXTLINE(performance-unnecessary-value-param) - [](py::array_t) {}, - py::arg("a")); + "accept_double", [](const py::array_t &) {}, py::arg("a")); sm.def( "accept_double_forcecast", - // NOLINTNEXTLINE(performance-unnecessary-value-param) - [](py::array_t) {}, + [](const py::array_t &) {}, py::arg("a")); sm.def( "accept_double_c_style", - // NOLINTNEXTLINE(performance-unnecessary-value-param) - [](py::array_t) {}, + [](const py::array_t &) {}, py::arg("a")); sm.def( "accept_double_c_style_forcecast", - // NOLINTNEXTLINE(performance-unnecessary-value-param) - [](py::array_t) {}, + [](const py::array_t &) {}, py::arg("a")); sm.def( "accept_double_f_style", - // NOLINTNEXTLINE(performance-unnecessary-value-param) - [](py::array_t) {}, + [](const py::array_t &) {}, py::arg("a")); sm.def( "accept_double_f_style_forcecast", - // NOLINTNEXTLINE(performance-unnecessary-value-param) - [](py::array_t) {}, + [](const py::array_t &) {}, py::arg("a")); sm.def( - "accept_double_noconvert", - // NOLINTNEXTLINE(performance-unnecessary-value-param) - [](py::array_t) {}, - "a"_a.noconvert()); + "accept_double_noconvert", [](const py::array_t &) {}, "a"_a.noconvert()); sm.def( "accept_double_forcecast_noconvert", - // NOLINTNEXTLINE(performance-unnecessary-value-param) - [](py::array_t) {}, + [](const py::array_t &) {}, "a"_a.noconvert()); sm.def( "accept_double_c_style_noconvert", - // NOLINTNEXTLINE(performance-unnecessary-value-param) - [](py::array_t) {}, + [](const py::array_t &) {}, "a"_a.noconvert()); sm.def( "accept_double_c_style_forcecast_noconvert", - // NOLINTNEXTLINE(performance-unnecessary-value-param) - [](py::array_t) {}, + [](const py::array_t &) {}, "a"_a.noconvert()); sm.def( "accept_double_f_style_noconvert", - // NOLINTNEXTLINE(performance-unnecessary-value-param) - [](py::array_t) {}, + [](const py::array_t &) {}, "a"_a.noconvert()); sm.def( "accept_double_f_style_forcecast_noconvert", - // NOLINTNEXTLINE(performance-unnecessary-value-param) - [](py::array_t) {}, + [](const py::array_t &) {}, "a"_a.noconvert()); // Check that types returns correct npy format descriptor - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("test_fmt_desc_float", [](py::array_t) {}); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("test_fmt_desc_double", [](py::array_t) {}); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("test_fmt_desc_const_float", [](py::array_t) {}); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - sm.def("test_fmt_desc_const_double", [](py::array_t) {}); + sm.def("test_fmt_desc_float", [](const py::array_t &) {}); + sm.def("test_fmt_desc_double", [](const py::array_t &) {}); + sm.def("test_fmt_desc_const_float", [](const py::array_t &) {}); + sm.def("test_fmt_desc_const_double", [](const py::array_t &) {}); } diff --git a/tests/test_stl.cpp b/tests/test_stl.cpp index dc75762e85..1f308e1393 100644 --- a/tests/test_stl.cpp +++ b/tests/test_stl.cpp @@ -207,8 +207,7 @@ TEST_SUBMODULE(stl, m) { }, py::arg_v("x", std::nullopt, "None")); m.def("nodefer_none_optional", [](std::optional) { return true; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - m.def("nodefer_none_optional", [](py::none) { return false; }); + m.def("nodefer_none_optional", [](const py::none &) { return false; }); using opt_holder = OptionalHolder; py::class_(m, "OptionalHolder", "Class with optional member") @@ -299,12 +298,11 @@ TEST_SUBMODULE(stl, m) { m.def("stl_pass_by_pointer", [](std::vector* v) { return *v; }, "v"_a=nullptr); // #1258: pybind11/stl.h converts string to vector - // NOLINTNEXTLINE(performance-unnecessary-value-param) - m.def("func_with_string_or_vector_string_arg_overload", [](std::vector) { return 1; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - m.def("func_with_string_or_vector_string_arg_overload", [](std::list) { return 2; }); - // NOLINTNEXTLINE(performance-unnecessary-value-param) - m.def("func_with_string_or_vector_string_arg_overload", [](std::string) { return 3; }); + m.def("func_with_string_or_vector_string_arg_overload", + [](const std::vector &) { return 1; }); + m.def("func_with_string_or_vector_string_arg_overload", + [](const std::list &) { return 2; }); + m.def("func_with_string_or_vector_string_arg_overload", [](const std::string &) { return 3; }); class Placeholder { public: