Commit ddbc74c6 authored by Ralf W. Grosse-Kunstleve's avatar Ralf W. Grosse-Kunstleve Committed by Ralf W. Grosse-Kunstleve
Browse files

Adding .clang-tidy readability-braces-around-statements option.

clang-tidy automatic changes. NO manual changes.
parent 8581584e
......@@ -108,30 +108,35 @@ PYBIND11_PACKED(struct EnumStruct {
std::ostream& operator<<(std::ostream& os, const StringStruct& v) {
os << "a='";
for (size_t i = 0; i < 3 && (v.a[i] != 0); i++)
for (size_t i = 0; i < 3 && (v.a[i] != 0); i++) {
os << v.a[i];
}
os << "',b='";
for (size_t i = 0; i < 3 && (v.b[i] != 0); i++)
for (size_t i = 0; i < 3 && (v.b[i] != 0); i++) {
os << v.b[i];
}
return os << "'";
}
std::ostream& operator<<(std::ostream& os, const ArrayStruct& v) {
os << "a={";
for (int i = 0; i < 3; i++) {
if (i > 0)
if (i > 0) {
os << ',';
}
os << '{';
for (int j = 0; j < 3; j++)
for (int j = 0; j < 3; j++) {
os << v.a[i][j] << ',';
}
os << v.a[i][3] << '}';
}
os << "},b={" << v.b[0] << ',' << v.b[1];
os << "},c={" << int(v.c[0]) << ',' << int(v.c[1]) << ',' << int(v.c[2]);
os << "},d={";
for (int i = 0; i < 4; i++) {
if (i > 0)
if (i > 0) {
os << ',';
}
os << '{' << v.d[i][0] << ',' << v.d[i][1] << '}';
}
return os << '}';
......@@ -198,7 +203,9 @@ py::array_t<int32_t, 0> test_array_ctors(int i) {
auto fill = [](py::array arr) {
auto req = arr.request();
for (int i = 0; i < 6; i++) ((int32_t *) req.ptr)[i] = i + 1;
for (int i = 0; i < 6; i++) {
((int32_t *) req.ptr)[i] = i + 1;
}
return arr;
};
......@@ -373,32 +380,33 @@ TEST_SUBMODULE(numpy_dtypes, m) {
m.def("print_dtypes", []() {
py::list l;
for (const py::handle &d : {
py::dtype::of<SimpleStruct>(),
py::dtype::of<PackedStruct>(),
py::dtype::of<NestedStruct>(),
py::dtype::of<PartialStruct>(),
py::dtype::of<PartialNestedStruct>(),
py::dtype::of<StringStruct>(),
py::dtype::of<ArrayStruct>(),
py::dtype::of<EnumStruct>(),
py::dtype::of<StructWithUglyNames>(),
py::dtype::of<ComplexStruct>()
})
for (const py::handle &d : {py::dtype::of<SimpleStruct>(),
py::dtype::of<PackedStruct>(),
py::dtype::of<NestedStruct>(),
py::dtype::of<PartialStruct>(),
py::dtype::of<PartialNestedStruct>(),
py::dtype::of<StringStruct>(),
py::dtype::of<ArrayStruct>(),
py::dtype::of<EnumStruct>(),
py::dtype::of<StructWithUglyNames>(),
py::dtype::of<ComplexStruct>()}) {
l.append(py::str(d));
}
return l;
});
m.def("test_dtype_ctors", &test_dtype_ctors);
m.def("test_dtype_kind", [dtype_names]() {
py::list list;
for (auto& dt_name : dtype_names)
for (auto &dt_name : dtype_names) {
list.append(py::dtype(dt_name).kind());
}
return list;
});
m.def("test_dtype_char_", [dtype_names]() {
py::list list;
for (auto& dt_name : dtype_names)
for (auto &dt_name : dtype_names) {
list.append(py::dtype(dt_name).char_());
}
return list;
});
m.def("test_dtype_methods", []() {
......@@ -423,8 +431,9 @@ TEST_SUBMODULE(numpy_dtypes, m) {
if (non_empty) {
auto req = arr.request();
auto ptr = static_cast<StringStruct*>(req.ptr);
for (py::ssize_t i = 0; i < req.size * req.itemsize; i++)
static_cast<char*>(req.ptr)[i] = 0;
for (py::ssize_t i = 0; i < req.size * req.itemsize; i++) {
static_cast<char *>(req.ptr)[i] = 0;
}
ptr[1].a[0] = 'a'; ptr[1].b[0] = 'a';
ptr[2].a[0] = 'a'; ptr[2].b[0] = 'a';
ptr[3].a[0] = 'a'; ptr[3].b[0] = 'a';
......@@ -443,16 +452,22 @@ TEST_SUBMODULE(numpy_dtypes, m) {
py::array_t<ArrayStruct, 0> arr = mkarray_via_buffer<ArrayStruct>(n);
auto ptr = (ArrayStruct *) arr.mutable_data();
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < 3; j++)
for (size_t k = 0; k < 4; k++)
for (size_t j = 0; j < 3; j++) {
for (size_t k = 0; k < 4; k++) {
ptr[i].a[j][k] = char('A' + (i * 100 + j * 10 + k) % 26);
for (size_t j = 0; j < 2; j++)
}
}
for (size_t j = 0; j < 2; j++) {
ptr[i].b[j] = int32_t(i * 1000 + j);
for (size_t j = 0; j < 3; j++)
}
for (size_t j = 0; j < 3; j++) {
ptr[i].c[j] = uint8_t(i * 10 + j);
for (size_t j = 0; j < 4; j++)
for (size_t k = 0; k < 2; k++)
}
for (size_t j = 0; j < 4; j++) {
for (size_t k = 0; k < 2; k++) {
ptr[i].d[j][k] = float(i) * 100.0f + float(j) * 10.0f + float(k);
}
}
}
return arr;
});
......
......@@ -45,8 +45,9 @@ TEST_SUBMODULE(opaque_types, m) {
std::string ret = "Opaque list: [";
bool first = true;
for (const auto &entry : l) {
if (!first)
if (!first) {
ret += ", ";
}
ret += entry;
first = false;
}
......
......@@ -39,13 +39,15 @@ void wrap(py::module m) {
.def(py::pickle(
[](const py::object &self) {
py::dict d;
if (py::hasattr(self, "__dict__"))
if (py::hasattr(self, "__dict__")) {
d = self.attr("__dict__");
}
return py::make_tuple(self.attr("num"), d);
},
[](const py::tuple &t) {
if (t.size() != 2)
if (t.size() != 2) {
throw std::runtime_error("Invalid state!");
}
auto cpp_state = std::unique_ptr<SimpleBase>(new SimpleBaseTrampoline);
cpp_state->num = t[0].cast<int>();
auto py_state = t[1].cast<py::dict>();
......@@ -101,8 +103,9 @@ TEST_SUBMODULE(pickling, m) {
});
ignoreOldStyleInitWarnings([&pyPickleable]() {
pyPickleable.def("__setstate__", [](Pickleable &p, const py::tuple &t) {
if (t.size() != 3)
if (t.size() != 3) {
throw std::runtime_error("Invalid state!");
}
/* Invoke the constructor (need to use in-place version) */
new (&p) Pickleable(t[0].cast<std::string>());
......@@ -119,8 +122,9 @@ TEST_SUBMODULE(pickling, m) {
return py::make_tuple(p.value(), p.extra1(), p.extra2());
},
[](const py::tuple &t) {
if (t.size() != 3)
if (t.size() != 3) {
throw std::runtime_error("Invalid state!");
}
auto p = PickleableNew(t[0].cast<std::string>());
p.setExtra1(t[1].cast<int>());
......@@ -153,8 +157,9 @@ TEST_SUBMODULE(pickling, m) {
});
ignoreOldStyleInitWarnings([&pyPickleableWithDict]() {
pyPickleableWithDict.def("__setstate__", [](const py::object &self, const py::tuple &t) {
if (t.size() != 3)
if (t.size() != 3) {
throw std::runtime_error("Invalid state!");
}
/* Cast and construct */
auto &p = self.cast<PickleableWithDict &>();
new (&p) PickleableWithDict(t[0].cast<std::string>());
......@@ -174,8 +179,9 @@ TEST_SUBMODULE(pickling, m) {
return py::make_tuple(self.attr("value"), self.attr("extra"), self.attr("__dict__"));
},
[](const py::tuple &t) {
if (t.size() != 3)
if (t.size() != 3) {
throw std::runtime_error("Invalid state!");
}
auto cpp_state = PickleableWithDictNew(t[0].cast<std::string>());
cpp_state.extra = t[1].cast<int>();
......
......@@ -40,8 +40,9 @@ TEST_SUBMODULE(pytypes, m) {
});
m.def("print_list", [](const py::list &list) {
int index = 0;
for (auto item : list)
for (auto item : list) {
py::print("list item {}: {}"_s.format(index++, item));
}
});
// test_none
m.def("get_none", []{return py::none();});
......@@ -56,8 +57,9 @@ TEST_SUBMODULE(pytypes, m) {
return set;
});
m.def("print_set", [](const py::set &set) {
for (auto item : set)
for (auto item : set) {
py::print("key:", item);
}
});
m.def("set_contains",
[](const py::set &set, const py::object &key) { return set.contains(key); });
......@@ -66,8 +68,9 @@ TEST_SUBMODULE(pytypes, m) {
// test_dict
m.def("get_dict", []() { return py::dict("key"_a="value"); });
m.def("print_dict", [](const py::dict &dict) {
for (auto item : dict)
for (auto item : dict) {
py::print("key: {}, value={}"_s.format(item.first, item.second));
}
});
m.def("dict_keyword_constructor", []() {
auto d1 = py::dict("x"_a=1, "y"_a=2);
......@@ -405,9 +408,9 @@ TEST_SUBMODULE(pytypes, m) {
m.def("test_memoryview_from_buffer", [](bool is_unsigned) {
static const int16_t si16[] = { 3, 1, 4, 1, 5 };
static const uint16_t ui16[] = { 2, 7, 1, 8 };
if (is_unsigned)
return py::memoryview::from_buffer(
ui16, { 4 }, { sizeof(uint16_t) });
if (is_unsigned) {
return py::memoryview::from_buffer(ui16, {4}, {sizeof(uint16_t)});
}
return py::memoryview::from_buffer(si16, {5}, {sizeof(int16_t)});
});
......
......@@ -74,8 +74,9 @@ PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableIntPair>);
template <typename PythonType>
py::list test_random_access_iterator(PythonType x) {
if (x.size() < 5)
if (x.size() < 5) {
throw py::value_error("Please provide at least 5 elements for testing.");
}
auto checks = py::list();
auto assert_equal = [&checks](py::handle a, py::handle b) {
......@@ -125,8 +126,9 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
.def(py::init<int>())
.def("__getitem__", [](const Sliceable &s, const py::slice &slice) {
py::ssize_t start = 0, stop = 0, step = 0, slicelength = 0;
if (!slice.compute(s.size, &start, &stop, &step, &slicelength))
if (!slice.compute(s.size, &start, &stop, &step, &slicelength)) {
throw py::error_already_set();
}
int istart = static_cast<int>(start);
int istop = static_cast<int>(stop);
int istep = static_cast<int>(step);
......@@ -195,10 +197,14 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
}
bool operator==(const Sequence &s) const {
if (m_size != s.size()) return false;
for (size_t i = 0; i < m_size; ++i)
if (m_data[i] != s[i])
if (m_size != s.size()) {
return false;
}
for (size_t i = 0; i < m_size; ++i) {
if (m_data[i] != s[i]) {
return false;
}
}
return true;
}
bool operator!=(const Sequence &s) const { return !operator==(s); }
......@@ -207,16 +213,19 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
float &operator[](size_t index) { return m_data[index]; }
bool contains(float v) const {
for (size_t i = 0; i < m_size; ++i)
if (v == m_data[i])
for (size_t i = 0; i < m_size; ++i) {
if (v == m_data[i]) {
return true;
}
}
return false;
}
Sequence reversed() const {
Sequence result(m_size);
for (size_t i = 0; i < m_size; ++i)
for (size_t i = 0; i < m_size; ++i) {
result[m_size - i - 1] = m_data[i];
}
return result;
}
......@@ -235,14 +244,16 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
/// Bare bones interface
.def("__getitem__",
[](const Sequence &s, size_t i) {
if (i >= s.size())
if (i >= s.size()) {
throw py::index_error();
}
return s[i];
})
.def("__setitem__",
[](Sequence &s, size_t i, float v) {
if (i >= s.size())
if (i >= s.size()) {
throw py::index_error();
}
s[i] = v;
})
.def("__len__", &Sequence::size)
......@@ -257,8 +268,9 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
.def("__getitem__",
[](const Sequence &s, const py::slice &slice) -> Sequence * {
size_t start = 0, stop = 0, step = 0, slicelength = 0;
if (!slice.compute(s.size(), &start, &stop, &step, &slicelength))
if (!slice.compute(s.size(), &start, &stop, &step, &slicelength)) {
throw py::error_already_set();
}
auto *seq = new Sequence(slicelength);
for (size_t i = 0; i < slicelength; ++i) {
(*seq)[i] = s[start];
......@@ -269,11 +281,13 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
.def("__setitem__",
[](Sequence &s, const py::slice &slice, const Sequence &value) {
size_t start = 0, stop = 0, step = 0, slicelength = 0;
if (!slice.compute(s.size(), &start, &stop, &step, &slicelength))
if (!slice.compute(s.size(), &start, &stop, &step, &slicelength)) {
throw py::error_already_set();
if (slicelength != value.size())
}
if (slicelength != value.size()) {
throw std::runtime_error(
"Left and right hand size of slice assignment have different sizes!");
}
for (size_t i = 0; i < slicelength; ++i) {
s[start] = value[i];
start += step;
......
......@@ -113,8 +113,9 @@ public:
static void cleanupAllInstances() {
auto tmp = std::move(myobject4_instances);
myobject4_instances.clear();
for (auto o : tmp)
for (auto o : tmp) {
delete o;
}
}
private:
~MyObject4() {
......@@ -140,8 +141,9 @@ public:
static void cleanupAllInstances() {
auto tmp = std::move(myobject4a_instances);
myobject4a_instances.clear();
for (auto o : tmp)
for (auto o : tmp) {
delete o;
}
}
protected:
virtual ~MyObject4a() {
......@@ -445,8 +447,9 @@ TEST_SUBMODULE(smart_ptr, m) {
.def("add", &ElementList::add)
.def("get", [](ElementList &el) {
py::list list;
for (auto &e : el.l)
for (auto &e : el.l) {
list.append(py::cast(e));
}
return list;
});
}
......@@ -42,23 +42,27 @@ public:
template <class Container> Container *one_to_n(int n) {
auto v = new Container();
for (int i = 1; i <= n; i++)
for (int i = 1; i <= n; i++) {
v->emplace_back(i);
}
return v;
}
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));
for (int i = 1; i <= n; i++) {
m->emplace(int(i), E_nc(10 * i));
}
return m;
}
template <class NestMap> 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));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
(*m)[i].emplace(int(j * 10), E_nc(100 * j));
}
}
return m;
}
......@@ -98,9 +102,11 @@ TEST_SUBMODULE(stl_binders, m) {
m.def("get_nvnc", [](int n)
{
auto m = new std::map<int, std::vector<E_nc>>();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
(*m)[i].emplace_back(j);
}
}
return m;
});
py::bind_map<std::map<int, std::map<int, E_nc>>>(m, "MapMapENC");
......
......@@ -100,8 +100,12 @@ const std::type_info* Animal::type_of_kind(Kind kind)
case Kind::LastCat: break;
}
if (kind >= Kind::Dog && kind <= Kind::LastDog) return &typeid(Dog);
if (kind >= Kind::Cat && kind <= Kind::LastCat) return &typeid(Cat);
if (kind >= Kind::Dog && kind <= Kind::LastDog) {
return &typeid(Dog);
}
if (kind >= Kind::Cat && kind <= Kind::LastCat) {
return &typeid(Cat);
}
return nullptr;
}
......
......@@ -112,8 +112,9 @@ public:
void operator=(const NonCopyable &) = delete;
void operator=(NonCopyable &&) = delete;
std::string get_value() const {
if (value)
if (value) {
return std::to_string(*value);
}
return "(null)";
}
~NonCopyable() { print_destroyed(this); }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment