Skip to content

Commit 08a97da

Browse files
committed
Merge branch 'master' into sh_merge_master
2 parents c55ee33 + f33f6af commit 08a97da

25 files changed

+107
-154
lines changed

.pre-commit-config.yaml

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@ repos:
2525

2626
# Clang format the codebase automatically
2727
- repo: https://github.com/pre-commit/mirrors-clang-format
28-
rev: "v17.0.6"
28+
rev: "v18.1.2"
2929
hooks:
3030
- id: clang-format
3131
types_or: [c++, c, cuda]
3232

3333
# Ruff, the Python auto-correcting linter/formatter written in Rust
3434
- repo: https://github.com/astral-sh/ruff-pre-commit
35-
rev: v0.2.0
35+
rev: v0.3.5
3636
hooks:
3737
- id: ruff
3838
args: ["--fix", "--show-fixes"]
3939
- id: ruff-format
4040

4141
# Check static types with mypy
4242
- repo: https://github.com/pre-commit/mirrors-mypy
43-
rev: "v1.8.0"
43+
rev: "v1.9.0"
4444
hooks:
4545
- id: mypy
4646
args: []
4747
exclude: ^(tests|docs)/
4848
additional_dependencies:
49-
- markdown-it-py<3 # Drop this together with dropping Python 3.7 support.
49+
- markdown-it-py
5050
- nox
5151
- rich
5252
- types-setuptools
@@ -88,14 +88,14 @@ repos:
8888

8989
# Changes tabs to spaces
9090
- repo: https://github.com/Lucas-C/pre-commit-hooks
91-
rev: "v1.5.4"
91+
rev: "v1.5.5"
9292
hooks:
9393
- id: remove-tabs
9494
exclude: (^docs/.*|\.patch)?$
9595

9696
# Avoid directional quotes
9797
- repo: https://github.com/sirosen/texthooks
98-
rev: "0.6.4"
98+
rev: "0.6.6"
9999
hooks:
100100
- id: fix-ligatures
101101
- id: fix-smartquotes
@@ -129,7 +129,7 @@ repos:
129129

130130
# Check for common shell mistakes
131131
- repo: https://github.com/shellcheck-py/shellcheck-py
132-
rev: "v0.9.0.6"
132+
rev: "v0.10.0.1"
133133
hooks:
134134
- id: shellcheck
135135

@@ -144,13 +144,13 @@ repos:
144144

145145
# PyLint has native support - not always usable, but works for us
146146
- repo: https://github.com/PyCQA/pylint
147-
rev: "v3.0.3"
147+
rev: "v3.1.0"
148148
hooks:
149149
- id: pylint
150150
files: ^pybind11
151151

152152
- repo: https://github.com/python-jsonschema/check-jsonschema
153-
rev: 0.28.0
153+
rev: 0.28.1
154154
hooks:
155155
- id: check-readthedocs
156156
- id: check-github-workflows

include/pybind11/buffer_info.h

+14-14
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,22 @@ struct buffer_info {
102102
template <typename T>
103103
buffer_info(const T *ptr, ssize_t size, bool readonly = true)
104104
: buffer_info(
105-
const_cast<T *>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) {}
105+
const_cast<T *>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) {}
106106

107107
explicit buffer_info(Py_buffer *view, bool ownview = true)
108108
: buffer_info(
109-
view->buf,
110-
view->itemsize,
111-
view->format,
112-
view->ndim,
113-
{view->shape, view->shape + view->ndim},
114-
/* Though buffer::request() requests PyBUF_STRIDES, ctypes objects
115-
* ignore this flag and return a view with NULL strides.
116-
* When strides are NULL, build them manually. */
117-
view->strides
118-
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
119-
: detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
120-
(view->readonly != 0)) {
109+
view->buf,
110+
view->itemsize,
111+
view->format,
112+
view->ndim,
113+
{view->shape, view->shape + view->ndim},
114+
/* Though buffer::request() requests PyBUF_STRIDES, ctypes objects
115+
* ignore this flag and return a view with NULL strides.
116+
* When strides are NULL, build them manually. */
117+
view->strides
118+
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
119+
: detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
120+
(view->readonly != 0)) {
121121
// NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
122122
this->m_view = view;
123123
// NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
@@ -176,7 +176,7 @@ struct buffer_info {
176176
detail::any_container<ssize_t> &&strides_in,
177177
bool readonly)
178178
: buffer_info(
179-
ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {}
179+
ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {}
180180

181181
Py_buffer *m_view = nullptr;
182182
bool ownview = false;

include/pybind11/detail/common.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,7 @@ using is_template_base_of
949949
= decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T> *) nullptr));
950950
#else
951951
struct is_template_base_of
952-
: decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T> *) nullptr)) {
953-
};
952+
: decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T> *) nullptr)){};
954953
#endif
955954

956955
/// Check if T is an instantiation of the template `Class`. For example:
@@ -1132,14 +1131,14 @@ struct overload_cast_impl {
11321131
}
11331132

11341133
template <typename Return, typename Class>
1135-
constexpr auto operator()(Return (Class::*pmf)(Args...), std::false_type = {}) const noexcept
1136-
-> decltype(pmf) {
1134+
constexpr auto operator()(Return (Class::*pmf)(Args...),
1135+
std::false_type = {}) const noexcept -> decltype(pmf) {
11371136
return pmf;
11381137
}
11391138

11401139
template <typename Return, typename Class>
1141-
constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept
1142-
-> decltype(pmf) {
1140+
constexpr auto operator()(Return (Class::*pmf)(Args...) const,
1141+
std::true_type) const noexcept -> decltype(pmf) {
11431142
return pmf;
11441143
}
11451144
};

include/pybind11/detail/descr.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ constexpr auto concat(const descr<N, Ts...> &d, const Args &...args) {
256256
}
257257
#else
258258
template <size_t N, typename... Ts, typename... Args>
259-
constexpr auto concat(const descr<N, Ts...> &d, const Args &...args)
260-
-> decltype(std::declval<descr<N + 2, Ts...>>() + concat(args...)) {
261-
// Ensure that src_loc of existing descr is used.
262-
return d + const_name(", ", src_loc{nullptr, 0}) + concat(args...);
259+
constexpr auto concat(const descr<N, Ts...> &d,
260+
const Args &...args) -> decltype(std::declval<descr<N + 2, Ts...>>()
261+
+ concat(args...)) {
262+
return d + const_name(", ") + concat(args...);
263263
}
264264
#endif
265265

include/pybind11/detail/internals.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,13 @@ struct type_info {
329329

330330
#define PYBIND11_INTERNALS_ID \
331331
"__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
332-
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \
333-
PYBIND11_BUILD_TYPE PYBIND11_INTERNALS_SH_DEF "__"
332+
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB \
333+
PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
334334

335335
#define PYBIND11_MODULE_LOCAL_ID \
336336
"__pybind11_module_local_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
337-
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \
338-
PYBIND11_BUILD_TYPE PYBIND11_INTERNALS_SH_DEF "__"
337+
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB \
338+
PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
339339

340340
/// Each module locally stores a pointer to the `internals` data. The data
341341
/// itself is shared among modules with the same `PYBIND11_INTERNALS_ID`.

include/pybind11/detail/type_caster_base.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1188,14 +1188,14 @@ class type_caster_base : public type_caster_generic {
11881188
does not have a private operator new implementation. A comma operator is used in the
11891189
decltype argument to apply SFINAE to the public copy/move constructors.*/
11901190
template <typename T, typename = enable_if_t<is_copy_constructible<T>::value>>
1191-
static auto make_copy_constructor(const T *)
1192-
-> decltype(new T(std::declval<const T>()), Constructor{}) {
1191+
static auto make_copy_constructor(const T *) -> decltype(new T(std::declval<const T>()),
1192+
Constructor{}) {
11931193
return [](const void *arg) -> void * { return new T(*reinterpret_cast<const T *>(arg)); };
11941194
}
11951195

11961196
template <typename T, typename = enable_if_t<is_move_constructible<T>::value>>
1197-
static auto make_move_constructor(const T *)
1198-
-> decltype(new T(std::declval<T &&>()), Constructor{}) {
1197+
static auto make_move_constructor(const T *) -> decltype(new T(std::declval<T &&>()),
1198+
Constructor{}) {
11991199
return [](const void *arg) -> void * {
12001200
return new T(std::move(*const_cast<T *>(reinterpret_cast<const T *>(arg))));
12011201
};

include/pybind11/stl_bind.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ void vector_modifiers(
158158
return v.release();
159159
}));
160160

161-
cl.def(
162-
"clear", [](Vector &v) { v.clear(); }, "Clear the contents");
161+
cl.def("clear", [](Vector &v) { v.clear(); }, "Clear the contents");
163162

164163
cl.def(
165164
"extend",

pybind11/setup_helpers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def no_recompile(obg: str, src: str) -> bool: # noqa: ARG001
353353
distutils.ccompiler.CCompiler,
354354
List[str],
355355
Optional[str],
356-
Optional[Union[Tuple[str], Tuple[str, Optional[str]]]],
356+
Optional[List[Union[Tuple[str], Tuple[str, Optional[str]]]]],
357357
Optional[List[str]],
358358
bool,
359359
Optional[List[str]],
@@ -429,7 +429,7 @@ def compile_function(
429429
compiler: distutils.ccompiler.CCompiler,
430430
sources: List[str],
431431
output_dir: Optional[str] = None,
432-
macros: Optional[Union[Tuple[str], Tuple[str, Optional[str]]]] = None,
432+
macros: Optional[List[Union[Tuple[str], Tuple[str, Optional[str]]]]] = None,
433433
include_dirs: Optional[List[str]] = None,
434434
debug: bool = False,
435435
extra_preargs: Optional[List[str]] = None,

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ignore = [
1919

2020
[tool.mypy]
2121
files = ["pybind11"]
22-
python_version = "3.7"
22+
python_version = "3.8"
2323
strict = true
2424
show_error_codes = true
2525
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]

tests/test_builtin_casters.cpp

+9-14
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ TEST_SUBMODULE(builtin_casters, m) {
102102
} // 𝐀, utf16
103103
else {
104104
wstr.push_back((wchar_t) mathbfA32);
105-
} // 𝐀, utf32
105+
} // 𝐀, utf32
106106
wstr.push_back(0x7a); // z
107107

108108
m.def("good_utf8_string", []() {
@@ -111,10 +111,9 @@ TEST_SUBMODULE(builtin_casters, m) {
111111
m.def("good_utf16_string", [=]() {
112112
return std::u16string({b16, ib16, cake16_1, cake16_2, mathbfA16_1, mathbfA16_2, z16});
113113
}); // b‽🎂𝐀z
114-
m.def("good_utf32_string", [=]() {
115-
return std::u32string({a32, mathbfA32, cake32, ib32, z32});
116-
}); // a𝐀🎂‽z
117-
m.def("good_wchar_string", [=]() { return wstr; }); // a‽𝐀z
114+
m.def("good_utf32_string",
115+
[=]() { return std::u32string({a32, mathbfA32, cake32, ib32, z32}); }); // a𝐀🎂‽z
116+
m.def("good_wchar_string", [=]() { return wstr; }); // a‽𝐀z
118117
m.def("bad_utf8_string", []() {
119118
return std::string("abc\xd0"
120119
"def");
@@ -124,9 +123,8 @@ TEST_SUBMODULE(builtin_casters, m) {
124123
// UnicodeDecodeError
125124
m.def("bad_utf32_string", [=]() { return std::u32string({a32, char32_t(0xd800), z32}); });
126125
if (sizeof(wchar_t) == 2) {
127-
m.def("bad_wchar_string", [=]() {
128-
return std::wstring({wchar_t(0x61), wchar_t(0xd800)});
129-
});
126+
m.def("bad_wchar_string",
127+
[=]() { return std::wstring({wchar_t(0x61), wchar_t(0xd800)}); });
130128
}
131129
m.def("u8_Z", []() -> char { return 'Z'; });
132130
m.def("u8_eacute", []() -> char { return '\xe9'; });
@@ -243,8 +241,7 @@ TEST_SUBMODULE(builtin_casters, m) {
243241

244242
// test_int_convert
245243
m.def("int_passthrough", [](int arg) { return arg; });
246-
m.def(
247-
"int_passthrough_noconvert", [](int arg) { return arg; }, py::arg{}.noconvert());
244+
m.def("int_passthrough_noconvert", [](int arg) { return arg; }, py::arg{}.noconvert());
248245

249246
// test_tuple
250247
m.def(
@@ -309,17 +306,15 @@ TEST_SUBMODULE(builtin_casters, m) {
309306

310307
// test_bool_caster
311308
m.def("bool_passthrough", [](bool arg) { return arg; });
312-
m.def(
313-
"bool_passthrough_noconvert", [](bool arg) { return arg; }, py::arg{}.noconvert());
309+
m.def("bool_passthrough_noconvert", [](bool arg) { return arg; }, py::arg{}.noconvert());
314310

315311
// TODO: This should be disabled and fixed in future Intel compilers
316312
#if !defined(__INTEL_COMPILER)
317313
// Test "bool_passthrough_noconvert" again, but using () instead of {} to construct py::arg
318314
// When compiled with the Intel compiler, this results in segmentation faults when importing
319315
// the module. Tested with icc (ICC) 2021.1 Beta 20200827, this should be tested again when
320316
// a newer version of icc is available.
321-
m.def(
322-
"bool_passthrough_noconvert2", [](bool arg) { return arg; }, py::arg().noconvert());
317+
m.def("bool_passthrough_noconvert2", [](bool arg) { return arg; }, py::arg().noconvert());
323318
#endif
324319

325320
// test_reference_wrapper

tests/test_call_policies.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ TEST_SUBMODULE(call_policies, m) {
6363
.def("returnNullChildKeepAliveParent", &Parent::returnNullChild, py::keep_alive<0, 1>())
6464
.def_static("staticFunction", &Parent::staticFunction, py::keep_alive<1, 0>());
6565

66-
m.def(
67-
"free_function", [](Parent *, Child *) {}, py::keep_alive<1, 2>());
68-
m.def(
69-
"invalid_arg_index", [] {}, py::keep_alive<0, 1>());
66+
m.def("free_function", [](Parent *, Child *) {}, py::keep_alive<1, 2>());
67+
m.def("invalid_arg_index", [] {}, py::keep_alive<0, 1>());
7068

7169
#if !defined(PYPY_VERSION)
7270
// test_alive_gc

tests/test_class.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ TEST_SUBMODULE(class_, m) {
475475
py::class_<Nested>(base, "Nested")
476476
.def(py::init<>())
477477
.def("fn", [](Nested &, int, NestBase &, Nested &) {})
478-
.def(
479-
"fa", [](Nested &, int, NestBase &, Nested &) {}, "a"_a, "b"_a, "c"_a);
478+
.def("fa", [](Nested &, int, NestBase &, Nested &) {}, "a"_a, "b"_a, "c"_a);
480479
base.def("g", [](NestBase &, Nested &) {});
481480
base.def("h", []() { return NestBase(); });
482481

tests/test_copy_move.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ TEST_SUBMODULE(copy_move_policies, m) {
289289
"get_moveissue1",
290290
[](int i) { return std::unique_ptr<MoveIssue1>(new MoveIssue1(i)); },
291291
py::return_value_policy::move);
292-
m.def(
293-
"get_moveissue2", [](int i) { return MoveIssue2(i); }, py::return_value_policy::move);
292+
m.def("get_moveissue2", [](int i) { return MoveIssue2(i); }, py::return_value_policy::move);
294293

295294
// Make sure that cast from pytype rvalue to other pytype works
296295
m.def("get_pytype_rvalue_castissue", [](double i) { return py::float_(i).cast<py::int_>(); });

tests/test_custom_type_casters.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,10 @@ TEST_SUBMODULE(custom_type_casters, m) {
185185
py::arg_v(nullptr, ArgInspector1()).noconvert(true),
186186
py::arg() = ArgAlwaysConverts());
187187

188-
m.def(
189-
"floats_preferred", [](double f) { return 0.5 * f; }, "f"_a);
190-
m.def(
191-
"floats_only", [](double f) { return 0.5 * f; }, "f"_a.noconvert());
192-
m.def(
193-
"ints_preferred", [](int i) { return i / 2; }, "i"_a);
194-
m.def(
195-
"ints_only", [](int i) { return i / 2; }, "i"_a.noconvert());
188+
m.def("floats_preferred", [](double f) { return 0.5 * f; }, "f"_a);
189+
m.def("floats_only", [](double f) { return 0.5 * f; }, "f"_a.noconvert());
190+
m.def("ints_preferred", [](int i) { return i / 2; }, "i"_a);
191+
m.def("ints_only", [](int i) { return i / 2; }, "i"_a.noconvert());
196192

197193
// test_custom_caster_destruction
198194
// Test that `take_ownership` works on types with a custom type caster when given a pointer

0 commit comments

Comments
 (0)