Skip to content

Commit ed9f340

Browse files
style: pre-commit fixes
1 parent 46280a7 commit ed9f340

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

tests/test_class_sh_virtual_py_cpp_mix.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,25 @@ int get_from_cpp_plainc_ptr(const Base *b) { return b->get() + 4000; }
2929

3030
int get_from_cpp_unique_ptr(std::unique_ptr<Base> b) { return b->get() + 5000; }
3131

32-
3332
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
3433

35-
struct VirtualItem
36-
{
34+
struct VirtualItem {
3735
VirtualItem() = default;
3836
virtual ~VirtualItem() = default;
3937
virtual int get() const = 0;
4038
};
4139

42-
struct VirtualItemTrampoline : public VirtualItem, py::trampoline_self_life_support
43-
{
40+
struct VirtualItemTrampoline : public VirtualItem, py::trampoline_self_life_support {
4441
int get() const override { PYBIND11_OVERRIDE_PURE(int, VirtualItem, get, ); }
4542
};
4643

47-
struct VirtualItemContainer
48-
{
44+
struct VirtualItemContainer {
4945
std::shared_ptr<VirtualItem> held;
5046
// ...
5147
};
5248

53-
void cpp_space_test(std::shared_ptr<VirtualItemContainer> container_vec)
54-
{
55-
auto i = container_vec->held->get(); // segfaults
49+
void cpp_space_test(std::shared_ptr<VirtualItemContainer> container_vec) {
50+
auto i = container_vec->held->get(); // segfaults
5651
}
5752

5853
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@@ -88,12 +83,10 @@ TEST_SUBMODULE(class_sh_virtual_py_cpp_mix, m) {
8883

8984
py::classh<VirtualItem, VirtualItemTrampoline>(m, "VirtualItem")
9085
.def(py::init<>())
91-
.def("get", &VirtualItem::get)
92-
;
86+
.def("get", &VirtualItem::get);
9387

9488
py::classh<VirtualItemContainer>(m, "VirtualItemContainer")
95-
.def(py::init<std::shared_ptr<VirtualItem>>())
96-
;
89+
.def(py::init<std::shared_ptr<VirtualItem>>());
9790

9891
m.def("cpp_space_test", cpp_space_test);
9992

tests/test_class_sh_virtual_py_cpp_mix.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@ def test_get_from_cpp_unique_ptr(ctor, expected):
6565
obj = ctor()
6666
assert m.get_from_cpp_unique_ptr(obj) == expected
6767

68+
6869
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
6970

71+
7072
class VirtualItemDerived(m.VirtualItem):
7173
def getInt(self):
7274
return 42
7375

76+
7477
def test_cpp_space_test():
7578
m.cpp_space_test(m.VirtualItemContainer(VirtualItemDerived()))
7679

80+
7781
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

tests/test_with_catch/test_interpreter.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,41 +93,35 @@ PYBIND11_EMBEDDED_MODULE(throw_error_already_set, ) {
9393

9494
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
9595

96-
97-
struct Item
98-
{
96+
struct Item {
9997
Item() = default;
10098
virtual ~Item() = default;
10199
virtual int getInt() const = 0;
102100
};
103101

104-
struct ItemTrampoline : public Item, py::trampoline_self_life_support
105-
{
102+
struct ItemTrampoline : public Item, py::trampoline_self_life_support {
106103
int getInt() const override { PYBIND11_OVERRIDE_PURE(int, Item, getInt, ); }
107104
};
108105

109106
PYBIND11_EMBEDDED_MODULE(embedded_smart_holder, m) {
110107

111-
py::classh<Item, ItemTrampoline>(m, "Item")
112-
.def(py::init<>())
113-
.def("getInt", &Item::getInt)
114-
;
108+
py::classh<Item, ItemTrampoline>(m, "Item").def(py::init<>()).def("getInt", &Item::getInt);
115109
}
116110

117111
TEST_CASE("Embedded smart holder test") {
118112

119113
auto module = py::module_::import("embedded_smart_holder");
120114

121-
auto o = module.attr("Item")(); // create py
115+
auto o = module.attr("Item")(); // create py
122116

123-
auto i = o.cast<std::shared_ptr<Item>>(); // cast cpp
117+
auto i = o.cast<std::shared_ptr<Item>>(); // cast cpp
124118

125-
if (i->getInt() != 42) // test cpp
119+
if (i->getInt() != 42) // test cpp
126120
throw std::runtime_error("Not 42");
127121

128122
o = py::object(); // release py
129123

130-
if (i->getInt() != 42) // test cpp
124+
if (i->getInt() != 42) // test cpp
131125
throw std::runtime_error("Not 42 after release");
132126
}
133127

0 commit comments

Comments
 (0)