Skip to content

Commit 05c8b9b

Browse files
committed
Automatic pre-commit run --all-files and clang-tidy changes (NO manual changes).
1 parent d5e302c commit 05c8b9b

36 files changed

+236
-227
lines changed

include/pybind11/detail/init.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,10 @@ void construct(value_and_holder &v_h, std::unique_ptr<Cpp<Class>, D> &&unq_ptr,
206206
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(need_alias);
207207
auto *ptr = unq_ptr.get();
208208
no_nullptr(ptr);
209-
if (PYBIND11_SILENCE_MSVC_C4127(Class::has_alias) && need_alias && !is_alias<Class>(ptr))
209+
if (PYBIND11_SILENCE_MSVC_C4127(Class::has_alias) && need_alias && !is_alias<Class>(ptr)) {
210210
throw type_error("pybind11::init(): construction failed: returned std::unique_ptr pointee "
211211
"is not an alias instance");
212+
}
212213
// Here and below: if the new object is a trampoline, the shared_from_this mechanism needs
213214
// to be prevented from accessing the smart_holder vptr, because it does not keep the
214215
// trampoline Python object alive. For types that don't inherit from enable_shared_from_this
@@ -242,9 +243,10 @@ void construct(value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, boo
242243
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(need_alias);
243244
auto *ptr = shd_ptr.get();
244245
no_nullptr(ptr);
245-
if (PYBIND11_SILENCE_MSVC_C4127(Class::has_alias) && need_alias && !is_alias<Class>(ptr))
246+
if (PYBIND11_SILENCE_MSVC_C4127(Class::has_alias) && need_alias && !is_alias<Class>(ptr)) {
246247
throw type_error("pybind11::init(): construction failed: returned std::shared_ptr pointee "
247248
"is not an alias instance");
249+
}
248250
auto smhldr = type_caster<Cpp<Class>>::template smart_holder_from_shared_ptr(shd_ptr);
249251
v_h.value_ptr() = ptr;
250252
v_h.type->init_instance(v_h.inst, &smhldr);

include/pybind11/detail/smart_holder_poc.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ struct guarded_delete {
7474
guarded_delete(void (*del_ptr)(void *), bool armed_flag)
7575
: del_ptr{del_ptr}, armed_flag{armed_flag} {}
7676
void operator()(void *raw_ptr) const {
77-
if (armed_flag)
77+
if (armed_flag) {
7878
(*del_ptr)(raw_ptr);
79+
}
7980
}
8081
};
8182

@@ -138,9 +139,10 @@ struct smart_holder {
138139

139140
template <typename T>
140141
static void ensure_pointee_is_destructible(const char *context) {
141-
if (!std::is_destructible<T>::value)
142+
if (!std::is_destructible<T>::value) {
142143
throw std::invalid_argument(std::string("Pointee is not destructible (") + context
143144
+ ").");
145+
}
144146
}
145147

146148
void ensure_is_populated(const char *context) const {
@@ -207,7 +209,7 @@ struct smart_holder {
207209
}
208210

209211
void reset_vptr_deleter_armed_flag(bool armed_flag) const {
210-
auto vptr_del_ptr = std::get_deleter<guarded_delete>(vptr);
212+
auto *vptr_del_ptr = std::get_deleter<guarded_delete>(vptr);
211213
if (vptr_del_ptr == nullptr) {
212214
throw std::runtime_error(
213215
"smart_holder::reset_vptr_deleter_armed_flag() called in an invalid context.");
@@ -249,10 +251,11 @@ struct smart_holder {
249251
ensure_pointee_is_destructible<T>("from_raw_ptr_take_ownership");
250252
smart_holder hld;
251253
auto gd = make_guarded_builtin_delete<T>(true);
252-
if (void_cast_raw_ptr)
254+
if (void_cast_raw_ptr) {
253255
hld.vptr.reset(static_cast<void *>(raw_ptr), std::move(gd));
254-
else
256+
} else {
255257
hld.vptr.reset(raw_ptr, std::move(gd));
258+
}
256259
hld.vptr_is_using_builtin_delete = true;
257260
hld.is_populated = true;
258261
return hld;
@@ -301,14 +304,16 @@ struct smart_holder {
301304
hld.rtti_uqp_del = &typeid(D);
302305
hld.vptr_is_using_builtin_delete = is_std_default_delete<T>(*hld.rtti_uqp_del);
303306
guarded_delete gd{nullptr, false};
304-
if (hld.vptr_is_using_builtin_delete)
307+
if (hld.vptr_is_using_builtin_delete) {
305308
gd = make_guarded_builtin_delete<T>(true);
306-
else
309+
} else {
307310
gd = make_guarded_custom_deleter<T, D>(true);
308-
if (void_cast_raw_ptr)
311+
}
312+
if (void_cast_raw_ptr) {
309313
hld.vptr.reset(static_cast<void *>(unq_ptr.get()), std::move(gd));
310-
else
314+
} else {
311315
hld.vptr.reset(unq_ptr.get(), std::move(gd));
316+
}
312317
(void) unq_ptr.release();
313318
hld.is_populated = true;
314319
return hld;

include/pybind11/detail/smart_holder_type_casters.h

Lines changed: 130 additions & 92 deletions
Large diffs are not rendered by default.

include/pybind11/smart_holder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
#pragma once
66

7+
#include "pybind11.h"
78
#include "detail/common.h"
89
#include "detail/smart_holder_type_casters.h"
9-
#include "pybind11.h"
1010

1111
#undef PYBIND11_SH_AVL // Undoing #define in pybind11.h
1212

tests/test_class_sh_basic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include "pybind11_tests.h"
2-
31
#include <pybind11/smart_holder.h>
42

3+
#include "pybind11_tests.h"
4+
55
#include <memory>
66
#include <string>
77
#include <vector>

tests/test_class_sh_basic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Importing re before pytest after observing a PyPy CI flake when importing pytest first.
32
import re
43

tests/test_class_sh_disowning.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include "pybind11_tests.h"
2-
31
#include <pybind11/smart_holder.h>
42

3+
#include "pybind11_tests.h"
4+
55
#include <memory>
66

77
namespace pybind11_tests {

tests/test_class_sh_disowning.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import print_function
3-
41
import pytest
52

63
from pybind11_tests import class_sh_disowning as m

tests/test_class_sh_disowning_mi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include "pybind11_tests.h"
2-
31
#include <pybind11/smart_holder.h>
42

3+
#include "pybind11_tests.h"
4+
55
#include <memory>
66

77
namespace pybind11_tests {

tests/test_class_sh_disowning_mi.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import pytest
32

43
import env # noqa: F401
@@ -77,7 +76,7 @@ def __init__(self, i, j):
7776
m.Base2.__init__(self, j)
7877

7978

80-
class B1(object):
79+
class B1:
8180
def v(self):
8281
return 1
8382

@@ -119,7 +118,7 @@ def v(self):
119118
return 2
120119

121120

122-
class B3(object):
121+
class B3:
123122
def v(self):
124123
return 3
125124

tests/test_class_sh_factory_constructors.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include "pybind11_tests.h"
2-
31
#include <pybind11/smart_holder.h>
42

3+
#include "pybind11_tests.h"
4+
55
#include <memory>
66
#include <string>
77

tests/test_class_sh_factory_constructors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import pytest
32

43
from pybind11_tests import class_sh_factory_constructors as m

tests/test_class_sh_inheritance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include "pybind11_tests.h"
2-
31
#include <pybind11/smart_holder.h>
42

3+
#include "pybind11_tests.h"
4+
55
#include <memory>
66

77
namespace pybind11_tests {

tests/test_class_sh_inheritance.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
from pybind11_tests import class_sh_inheritance as m
42

53

tests/test_class_sh_module_local.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import class_sh_module_local_0 as m0
32
import class_sh_module_local_1 as m1
43
import class_sh_module_local_2 as m2

tests/test_class_sh_shared_ptr_copy_move.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include "pybind11_tests.h"
2-
31
#include <pybind11/smart_holder.h>
42

3+
#include "pybind11_tests.h"
4+
55
#include <memory>
66
#include <string>
77
#include <vector>

tests/test_class_sh_shared_ptr_copy_move.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
from pybind11_tests import class_sh_shared_ptr_copy_move as m
42

53

@@ -25,8 +23,8 @@ def test_smhld_move():
2523

2624
def _check_property(foo_typ, prop_typ, policy):
2725
o = m.Outer()
28-
name = "{}_{}_{}".format(foo_typ, prop_typ, policy)
29-
history = "Foo{}_Outer".format(foo_typ)
26+
name = f"{foo_typ}_{prop_typ}_{policy}"
27+
history = f"Foo{foo_typ}_Outer"
3028
f = getattr(o, name)
3129
assert f.get_history() == history
3230
# and try again to check that o did not get changed

tests/test_class_sh_trampoline_basic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include "pybind11_tests.h"
2-
31
#include <pybind11/smart_holder.h>
42

3+
#include "pybind11_tests.h"
4+
55
#include <memory>
66

77
namespace pybind11_tests {

tests/test_class_sh_trampoline_basic.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
# -*- coding: utf-8 -*-
21
import pytest
32

43
from pybind11_tests import class_sh_trampoline_basic as m
54

65

76
class PyDrvd0(m.Abase0):
87
def __init__(self, val):
9-
super(PyDrvd0, self).__init__(val)
8+
super().__init__(val)
109

1110
def Add(self, other_val): # noqa: N802
1211
return self.Get() * 100 + other_val
1312

1413

1514
class PyDrvd1(m.Abase1):
1615
def __init__(self, val):
17-
super(PyDrvd1, self).__init__(val)
16+
super().__init__(val)
1817

1918
def Add(self, other_val): # noqa: N802
2019
return self.Get() * 200 + other_val

tests/test_class_sh_trampoline_self_life_support.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ TEST_SUBMODULE(class_sh_trampoline_self_life_support, m) {
5454
py::object o2 = py::none();
5555
// This is very unusual, but needed to directly exercise the trampoline_self_life_support
5656
// CpCtor, MvCtor, operator= lvalue, operator= rvalue.
57-
auto obj_trampoline = dynamic_cast<Big5Trampoline *>(obj.get());
57+
auto *obj_trampoline = dynamic_cast<Big5Trampoline *>(obj.get());
5858
if (obj_trampoline != nullptr) {
5959
switch (action_id) {
6060
case 0: { // CpCtor

tests/test_class_sh_trampoline_self_life_support.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import pytest
32

43
import pybind11_tests.class_sh_trampoline_self_life_support as m

tests/test_class_sh_trampoline_shared_from_this.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ struct SftSharedPtrStash {
5757
stash.push_back(sft);
5858
}
5959
std::string history(unsigned i) {
60-
if (i < stash.size())
60+
if (i < stash.size()) {
6161
return stash[i]->history;
62+
}
6263
return "OutOfRange";
6364
}
6465
long use_count(unsigned i) {
65-
if (i < stash.size())
66+
if (i < stash.size()) {
6667
return stash[i].use_count();
68+
}
6769
return -1;
6870
}
6971
};

tests/test_class_sh_trampoline_shared_from_this.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import sys
32
import weakref
43

@@ -220,7 +219,7 @@ def test_multiple_registered_instances_for_same_pointee_recursive():
220219
def test_std_make_shared_factory():
221220
class PySftMakeShared(m.Sft):
222221
def __init__(self, history):
223-
super(PySftMakeShared, self).__init__(history, 0)
222+
super().__init__(history, 0)
224223

225224
obj = PySftMakeShared("PySftMakeShared")
226225
assert obj.history == "PySftMakeShared"

tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
#include <utility>
6-
75
#include "pybind11/smart_holder.h"
86
#include "pybind11_tests.h"
97

8+
#include <utility>
9+
1010
namespace {
1111

1212
// For testing whether a python subclass of a C++ object dies when the
@@ -17,7 +17,7 @@ struct SpBase {
1717

1818
// returns true if there's an associated python instance
1919
bool has_python_instance() {
20-
auto tinfo = py::detail::get_type_info(typeid(SpBase));
20+
auto *tinfo = py::detail::get_type_info(typeid(SpBase));
2121
return (bool) py::detail::get_object_handle(this, tinfo);
2222
}
2323

tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import pytest
32

43
import pybind11_tests.class_sh_trampoline_shared_ptr_cpp_arg as m
@@ -136,7 +135,7 @@ def test_infinite():
136135
def test_std_make_shared_factory():
137136
class PyChild(m.SpBase):
138137
def __init__(self):
139-
super(PyChild, self).__init__(0)
138+
super().__init__(0)
140139

141140
obj = PyChild()
142141
while True:

tests/test_class_sh_trampoline_unique_ptr.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import pybind11_tests.class_sh_trampoline_unique_ptr as m
42

53

tests/test_class_sh_unique_ptr_member.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include "pybind11_tests.h"
2-
31
#include <pybind11/smart_holder.h>
42

3+
#include "pybind11_tests.h"
4+
55
#include <memory>
66

77
namespace pybind11_tests {

tests/test_class_sh_unique_ptr_member.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import pytest
32

43
from pybind11_tests import class_sh_unique_ptr_member as m

tests/test_class_sh_virtual_py_cpp_mix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include "pybind11_tests.h"
2-
31
#include <pybind11/smart_holder.h>
42

3+
#include "pybind11_tests.h"
4+
55
#include <memory>
66

77
namespace pybind11_tests {

tests/test_class_sh_virtual_py_cpp_mix.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import pytest
32

43
from pybind11_tests import class_sh_virtual_py_cpp_mix as m

0 commit comments

Comments
 (0)