mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
fix(clang-tidy): performance fixes applied in tests and CI (#3051)
* Initial fixes * Whoops * Finish clang-tidy manual fixes * Add two missing fixes * Revert * Update clang-tidy * Try to fix unreachable code error * Move nolint comment * Apply missing fix * Don't override clang-tidy config * Does this fix clang-tidy? * Make all clang-tidy errors visible * Add comments about NOLINTs and remove a few * Fix typo
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include "constructor_stats.h"
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
TEST_SUBMODULE(kwargs_and_defaults, m) {
|
||||
auto kw_func = [](int x, int y) { return "x=" + std::to_string(x) + ", y=" + std::to_string(y); };
|
||||
|
||||
@@ -37,18 +39,16 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
|
||||
m.def("args_function", [](py::args args) -> py::tuple {
|
||||
return std::move(args);
|
||||
});
|
||||
m.def("args_kwargs_function", [](py::args args, py::kwargs kwargs) {
|
||||
m.def("args_kwargs_function", [](const py::args &args, const py::kwargs &kwargs) {
|
||||
return py::make_tuple(args, kwargs);
|
||||
});
|
||||
|
||||
// test_mixed_args_and_kwargs
|
||||
m.def("mixed_plus_args", [](int i, double j, py::args args) {
|
||||
return py::make_tuple(i, j, args);
|
||||
});
|
||||
m.def("mixed_plus_kwargs", [](int i, double j, py::kwargs kwargs) {
|
||||
return py::make_tuple(i, j, kwargs);
|
||||
});
|
||||
auto mixed_plus_both = [](int i, double j, py::args args, py::kwargs kwargs) {
|
||||
m.def("mixed_plus_args",
|
||||
[](int i, double j, const py::args &args) { return py::make_tuple(i, j, args); });
|
||||
m.def("mixed_plus_kwargs",
|
||||
[](int i, double j, const py::kwargs &kwargs) { return py::make_tuple(i, j, kwargs); });
|
||||
auto mixed_plus_both = [](int i, double j, const py::args &args, const py::kwargs &kwargs) {
|
||||
return py::make_tuple(i, j, args, kwargs);
|
||||
};
|
||||
m.def("mixed_plus_args_kwargs", mixed_plus_both);
|
||||
@@ -65,6 +65,8 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
|
||||
#endif
|
||||
m.def("arg_refcount_h", [](py::handle h) { GC_IF_NEEDED; return h.ref_count(); });
|
||||
m.def("arg_refcount_h", [](py::handle h, py::handle, py::handle) { GC_IF_NEEDED; return h.ref_count(); });
|
||||
// TODO replace the following nolints as appropiate
|
||||
// NOLINTNEXTLINE(performance-unnecessary-value-param)
|
||||
m.def("arg_refcount_o", [](py::object o) { GC_IF_NEEDED; return o.ref_count(); });
|
||||
m.def("args_refcount", [](py::args a) {
|
||||
GC_IF_NEEDED;
|
||||
@@ -74,6 +76,7 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
|
||||
t[i] = (int) Py_REFCNT(PyTuple_GET_ITEM(a.ptr(), static_cast<py::ssize_t>(i)));
|
||||
return t;
|
||||
});
|
||||
// NOLINTNEXTLINE(performance-unnecessary-value-param)
|
||||
m.def("mixed_args_refcount", [](py::object o, py::args a) {
|
||||
GC_IF_NEEDED;
|
||||
py::tuple t(a.size() + 1);
|
||||
@@ -103,6 +106,7 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
|
||||
py::arg() = 3, "j"_a = 4, py::kw_only(), "k"_a = 5, "z"_a);
|
||||
m.def("kw_only_mixed", [](int i, int j) { return py::make_tuple(i, j); },
|
||||
"i"_a, py::kw_only(), "j"_a);
|
||||
// NOLINTNEXTLINE(performance-unnecessary-value-param)
|
||||
m.def("kw_only_plus_more", [](int i, int j, int k, py::kwargs kwargs) {
|
||||
return py::make_tuple(i, j, k, kwargs); },
|
||||
py::arg() /* positional */, py::arg("j") = -1 /* both */, py::kw_only(), py::arg("k") /* kw-only */);
|
||||
@@ -137,6 +141,8 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
|
||||
|
||||
// Make sure a class (not an instance) can be used as a default argument.
|
||||
// The return value doesn't matter, only that the module is importable.
|
||||
m.def("class_default_argument", [](py::object a) { return py::repr(a); },
|
||||
m.def(
|
||||
"class_default_argument",
|
||||
[](py::object a) { return py::repr(std::move(a)); },
|
||||
"a"_a = py::module_::import("decimal").attr("Decimal"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user