Add more readability tidy rules (#5924)

* Apply clang-tidy readibility fixes

Signed-off-by: Yuanyuan Chen <cyyever@outlook.com>

* Add checks

Signed-off-by: Yuanyuan Chen <cyyever@outlook.com>

* More fixes

Signed-off-by: cyy <cyyever@outlook.com>

---------

Signed-off-by: Yuanyuan Chen <cyyever@outlook.com>
Signed-off-by: cyy <cyyever@outlook.com>
This commit is contained in:
Yuanyuan Chen
2025-12-09 01:36:51 +08:00
committed by GitHub
parent 6651530963
commit 3ebbecb8af
16 changed files with 36 additions and 37 deletions

View File

@@ -367,7 +367,7 @@ TEST_SUBMODULE(builtin_casters, m) {
m.def("complex_noconvert", [](std::complex<float> x) { return x; }, py::arg{}.noconvert());
// test int vs. long (Python 2)
m.def("int_cast", []() { return (int) 42; });
m.def("int_cast", []() { return 42; });
m.def("long_cast", []() { return (long) 42; });
m.def("longlong_cast", []() { return ULLONG_MAX; });

View File

@@ -36,9 +36,9 @@ struct PySpBase : SpBase, py::trampoline_self_life_support {
struct SpBaseTester {
std::shared_ptr<SpBase> get_object() const { return m_obj; }
void set_object(std::shared_ptr<SpBase> obj) { m_obj = std::move(obj); }
bool is_base_used() { return m_obj->is_base_used(); }
bool has_instance() { return (bool) m_obj; }
bool has_python_instance() { return m_obj && m_obj->has_python_instance(); }
bool is_base_used() const { return m_obj->is_base_used(); }
bool has_instance() const { return (bool) m_obj; }
bool has_python_instance() const { return m_obj && m_obj->has_python_instance(); }
void set_nonpython_instance() { m_obj = std::make_shared<SpBase>(); }
std::shared_ptr<SpBase> m_obj;
};

View File

@@ -73,7 +73,7 @@ public:
// Inheritance test
class TestFactory4 : public TestFactory3 {
public:
TestFactory4() : TestFactory3() { print_default_created(this); }
TestFactory4() { print_default_created(this); }
explicit TestFactory4(int v) : TestFactory3(v) { print_created(this, v); }
~TestFactory4() override { print_destroyed(this); }
};

View File

@@ -17,8 +17,8 @@
// Size / dtype checks.
struct DtypeCheck {
py::dtype numpy{};
py::dtype pybind11{};
py::dtype numpy;
py::dtype pybind11;
};
template <typename T>
@@ -43,11 +43,11 @@ std::vector<DtypeCheck> get_concrete_dtype_checks() {
}
struct DtypeSizeCheck {
std::string name{};
std::string name;
int size_cpp{};
int size_numpy{};
// For debugging.
py::dtype dtype{};
py::dtype dtype;
};
template <typename T>

View File

@@ -556,7 +556,7 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
});
m.def("count_nonzeros", [](const py::dict &d) {
return std::count_if(d.begin(), d.end(), [](std::pair<py::handle, py::handle> p) {
return std::count_if(d.begin(), d.end(), [](const std::pair<py::handle, py::handle> &p) {
return p.second.cast<int>() != 0;
});
});

View File

@@ -220,7 +220,7 @@ struct SharedPtrRef {
~A() { print_destroyed(this); }
};
A value = {};
A value;
std::shared_ptr<A> shared = std::make_shared<A>();
};
@@ -228,13 +228,14 @@ struct SharedPtrRef {
struct SharedFromThisRef {
struct B : std::enable_shared_from_this<B> {
B() { print_created(this); }
// NOLINTNEXTLINE(bugprone-copy-constructor-init)
// NOLINTNEXTLINE(bugprone-copy-constructor-init, readability-redundant-member-init)
B(const B &) : std::enable_shared_from_this<B>() { print_copy_created(this); }
// NOLINTNEXTLINE(readability-redundant-member-init)
B(B &&) noexcept : std::enable_shared_from_this<B>() { print_move_created(this); }
~B() { print_destroyed(this); }
};
B value = {};
B value;
std::shared_ptr<B> shared = std::make_shared<B>();
};

View File

@@ -55,7 +55,7 @@ template <class Map>
Map *times_ten(int n) {
auto *m = new Map();
for (int i = 1; i <= n; i++) {
m->emplace(int(i), E_nc(10 * i));
m->emplace(i, E_nc(10 * i));
}
return m;
}
@@ -65,7 +65,7 @@ NestMap *times_hundred(int n) {
auto *m = new NestMap();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
(*m)[i].emplace(int(j * 10), E_nc(100 * j));
(*m)[i].emplace(j * 10, E_nc(100 * j));
}
}
return m;