diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2cf3ed9f3f..b31d5738f4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,14 +25,14 @@ repos: # Clang format the codebase automatically - repo: https://github.com/pre-commit/mirrors-clang-format - rev: "v17.0.6" + rev: "v18.1.2" hooks: - id: clang-format types_or: [c++, c, cuda] # Ruff, the Python auto-correcting linter/formatter written in Rust - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.0 + rev: v0.3.5 hooks: - id: ruff args: ["--fix", "--show-fixes"] @@ -40,13 +40,13 @@ repos: # Check static types with mypy - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.8.0" + rev: "v1.9.0" hooks: - id: mypy args: [] exclude: ^(tests|docs)/ additional_dependencies: - - markdown-it-py<3 # Drop this together with dropping Python 3.7 support. + - markdown-it-py - nox - rich - types-setuptools @@ -88,14 +88,14 @@ repos: # Changes tabs to spaces - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: "v1.5.4" + rev: "v1.5.5" hooks: - id: remove-tabs exclude: (^docs/.*|\.patch)?$ # Avoid directional quotes - repo: https://github.com/sirosen/texthooks - rev: "0.6.4" + rev: "0.6.6" hooks: - id: fix-ligatures - id: fix-smartquotes @@ -129,7 +129,7 @@ repos: # Check for common shell mistakes - repo: https://github.com/shellcheck-py/shellcheck-py - rev: "v0.9.0.6" + rev: "v0.10.0.1" hooks: - id: shellcheck @@ -144,13 +144,13 @@ repos: # PyLint has native support - not always usable, but works for us - repo: https://github.com/PyCQA/pylint - rev: "v3.0.3" + rev: "v3.1.0" hooks: - id: pylint files: ^pybind11 - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.28.0 + rev: 0.28.1 hooks: - id: check-readthedocs - id: check-github-workflows diff --git a/include/pybind11/buffer_info.h b/include/pybind11/buffer_info.h index b99ee8bef4..75aec0ba30 100644 --- a/include/pybind11/buffer_info.h +++ b/include/pybind11/buffer_info.h @@ -102,22 +102,22 @@ struct buffer_info { template buffer_info(const T *ptr, ssize_t size, bool readonly = true) : buffer_info( - const_cast(ptr), sizeof(T), format_descriptor::format(), size, readonly) {} + const_cast(ptr), sizeof(T), format_descriptor::format(), size, readonly) {} explicit buffer_info(Py_buffer *view, bool ownview = true) : buffer_info( - view->buf, - view->itemsize, - view->format, - view->ndim, - {view->shape, view->shape + view->ndim}, - /* Though buffer::request() requests PyBUF_STRIDES, ctypes objects - * ignore this flag and return a view with NULL strides. - * When strides are NULL, build them manually. */ - view->strides - ? std::vector(view->strides, view->strides + view->ndim) - : detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize), - (view->readonly != 0)) { + view->buf, + view->itemsize, + view->format, + view->ndim, + {view->shape, view->shape + view->ndim}, + /* Though buffer::request() requests PyBUF_STRIDES, ctypes objects + * ignore this flag and return a view with NULL strides. + * When strides are NULL, build them manually. */ + view->strides + ? std::vector(view->strides, view->strides + view->ndim) + : detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize), + (view->readonly != 0)) { // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer) this->m_view = view; // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer) @@ -176,7 +176,7 @@ struct buffer_info { detail::any_container &&strides_in, bool readonly) : buffer_info( - ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {} + ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {} Py_buffer *m_view = nullptr; bool ownview = false; diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index dd8c88b574..55e25f3fc7 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -949,8 +949,7 @@ using is_template_base_of = decltype(is_template_base_of_impl::check((intrinsic_t *) nullptr)); #else struct is_template_base_of - : decltype(is_template_base_of_impl::check((intrinsic_t *) nullptr)) { -}; + : decltype(is_template_base_of_impl::check((intrinsic_t *) nullptr)){}; #endif /// Check if T is an instantiation of the template `Class`. For example: @@ -1132,14 +1131,14 @@ struct overload_cast_impl { } template - constexpr auto operator()(Return (Class::*pmf)(Args...), std::false_type = {}) const noexcept - -> decltype(pmf) { + constexpr auto operator()(Return (Class::*pmf)(Args...), + std::false_type = {}) const noexcept -> decltype(pmf) { return pmf; } template - constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept - -> decltype(pmf) { + constexpr auto operator()(Return (Class::*pmf)(Args...) const, + std::true_type) const noexcept -> decltype(pmf) { return pmf; } }; diff --git a/include/pybind11/detail/descr.h b/include/pybind11/detail/descr.h index d447046d36..d239830e2c 100644 --- a/include/pybind11/detail/descr.h +++ b/include/pybind11/detail/descr.h @@ -256,10 +256,10 @@ constexpr auto concat(const descr &d, const Args &...args) { } #else template -constexpr auto concat(const descr &d, const Args &...args) - -> decltype(std::declval>() + concat(args...)) { - // Ensure that src_loc of existing descr is used. - return d + const_name(", ", src_loc{nullptr, 0}) + concat(args...); +constexpr auto concat(const descr &d, + const Args &...args) -> decltype(std::declval>() + + concat(args...)) { + return d + const_name(", ") + concat(args...); } #endif diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 6af856a776..ccd19ed26f 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -329,13 +329,13 @@ struct type_info { #define PYBIND11_INTERNALS_ID \ "__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \ - PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \ - PYBIND11_BUILD_TYPE PYBIND11_INTERNALS_SH_DEF "__" + PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB \ + PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__" #define PYBIND11_MODULE_LOCAL_ID \ "__pybind11_module_local_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \ - PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \ - PYBIND11_BUILD_TYPE PYBIND11_INTERNALS_SH_DEF "__" + PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB \ + PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__" /// Each module locally stores a pointer to the `internals` data. The data /// itself is shared among modules with the same `PYBIND11_INTERNALS_ID`. diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 699369b791..ec1e73957c 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -1188,14 +1188,14 @@ class type_caster_base : public type_caster_generic { does not have a private operator new implementation. A comma operator is used in the decltype argument to apply SFINAE to the public copy/move constructors.*/ template ::value>> - static auto make_copy_constructor(const T *) - -> decltype(new T(std::declval()), Constructor{}) { + static auto make_copy_constructor(const T *) -> decltype(new T(std::declval()), + Constructor{}) { return [](const void *arg) -> void * { return new T(*reinterpret_cast(arg)); }; } template ::value>> - static auto make_move_constructor(const T *) - -> decltype(new T(std::declval()), Constructor{}) { + static auto make_move_constructor(const T *) -> decltype(new T(std::declval()), + Constructor{}) { return [](const void *arg) -> void * { return new T(std::move(*const_cast(reinterpret_cast(arg)))); }; diff --git a/include/pybind11/stl_bind.h b/include/pybind11/stl_bind.h index 3d24bc5a1c..a04e168645 100644 --- a/include/pybind11/stl_bind.h +++ b/include/pybind11/stl_bind.h @@ -158,8 +158,7 @@ void vector_modifiers( return v.release(); })); - cl.def( - "clear", [](Vector &v) { v.clear(); }, "Clear the contents"); + cl.def("clear", [](Vector &v) { v.clear(); }, "Clear the contents"); cl.def( "extend", diff --git a/pybind11/setup_helpers.py b/pybind11/setup_helpers.py index 3b16dca886..16ab76b28a 100644 --- a/pybind11/setup_helpers.py +++ b/pybind11/setup_helpers.py @@ -353,7 +353,7 @@ def no_recompile(obg: str, src: str) -> bool: # noqa: ARG001 distutils.ccompiler.CCompiler, List[str], Optional[str], - Optional[Union[Tuple[str], Tuple[str, Optional[str]]]], + Optional[List[Union[Tuple[str], Tuple[str, Optional[str]]]]], Optional[List[str]], bool, Optional[List[str]], @@ -429,7 +429,7 @@ def compile_function( compiler: distutils.ccompiler.CCompiler, sources: List[str], output_dir: Optional[str] = None, - macros: Optional[Union[Tuple[str], Tuple[str, Optional[str]]]] = None, + macros: Optional[List[Union[Tuple[str], Tuple[str, Optional[str]]]]] = None, include_dirs: Optional[List[str]] = None, debug: bool = False, extra_preargs: Optional[List[str]] = None, diff --git a/pyproject.toml b/pyproject.toml index 5af6015a6b..da02caa879 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ ignore = [ [tool.mypy] files = ["pybind11"] -python_version = "3.7" +python_version = "3.8" strict = true show_error_codes = true enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] diff --git a/tests/test_builtin_casters.cpp b/tests/test_builtin_casters.cpp index 64843162d5..4177b6d473 100644 --- a/tests/test_builtin_casters.cpp +++ b/tests/test_builtin_casters.cpp @@ -102,7 +102,7 @@ TEST_SUBMODULE(builtin_casters, m) { } // 𝐀, utf16 else { wstr.push_back((wchar_t) mathbfA32); - } // 𝐀, utf32 + } // 𝐀, utf32 wstr.push_back(0x7a); // z m.def("good_utf8_string", []() { @@ -111,10 +111,9 @@ TEST_SUBMODULE(builtin_casters, m) { m.def("good_utf16_string", [=]() { return std::u16string({b16, ib16, cake16_1, cake16_2, mathbfA16_1, mathbfA16_2, z16}); }); // b‽🎂𝐀z - m.def("good_utf32_string", [=]() { - return std::u32string({a32, mathbfA32, cake32, ib32, z32}); - }); // a𝐀🎂‽z - m.def("good_wchar_string", [=]() { return wstr; }); // a‽𝐀z + m.def("good_utf32_string", + [=]() { return std::u32string({a32, mathbfA32, cake32, ib32, z32}); }); // a𝐀🎂‽z + m.def("good_wchar_string", [=]() { return wstr; }); // a‽𝐀z m.def("bad_utf8_string", []() { return std::string("abc\xd0" "def"); @@ -124,9 +123,8 @@ TEST_SUBMODULE(builtin_casters, m) { // UnicodeDecodeError m.def("bad_utf32_string", [=]() { return std::u32string({a32, char32_t(0xd800), z32}); }); if (sizeof(wchar_t) == 2) { - m.def("bad_wchar_string", [=]() { - return std::wstring({wchar_t(0x61), wchar_t(0xd800)}); - }); + m.def("bad_wchar_string", + [=]() { return std::wstring({wchar_t(0x61), wchar_t(0xd800)}); }); } m.def("u8_Z", []() -> char { return 'Z'; }); m.def("u8_eacute", []() -> char { return '\xe9'; }); @@ -243,8 +241,7 @@ TEST_SUBMODULE(builtin_casters, m) { // test_int_convert m.def("int_passthrough", [](int arg) { return arg; }); - m.def( - "int_passthrough_noconvert", [](int arg) { return arg; }, py::arg{}.noconvert()); + m.def("int_passthrough_noconvert", [](int arg) { return arg; }, py::arg{}.noconvert()); // test_tuple m.def( @@ -309,8 +306,7 @@ TEST_SUBMODULE(builtin_casters, m) { // test_bool_caster m.def("bool_passthrough", [](bool arg) { return arg; }); - m.def( - "bool_passthrough_noconvert", [](bool arg) { return arg; }, py::arg{}.noconvert()); + m.def("bool_passthrough_noconvert", [](bool arg) { return arg; }, py::arg{}.noconvert()); // TODO: This should be disabled and fixed in future Intel compilers #if !defined(__INTEL_COMPILER) @@ -318,8 +314,7 @@ TEST_SUBMODULE(builtin_casters, m) { // When compiled with the Intel compiler, this results in segmentation faults when importing // the module. Tested with icc (ICC) 2021.1 Beta 20200827, this should be tested again when // a newer version of icc is available. - m.def( - "bool_passthrough_noconvert2", [](bool arg) { return arg; }, py::arg().noconvert()); + m.def("bool_passthrough_noconvert2", [](bool arg) { return arg; }, py::arg().noconvert()); #endif // test_reference_wrapper diff --git a/tests/test_call_policies.cpp b/tests/test_call_policies.cpp index d177008cfe..279012d45c 100644 --- a/tests/test_call_policies.cpp +++ b/tests/test_call_policies.cpp @@ -63,10 +63,8 @@ TEST_SUBMODULE(call_policies, m) { .def("returnNullChildKeepAliveParent", &Parent::returnNullChild, py::keep_alive<0, 1>()) .def_static("staticFunction", &Parent::staticFunction, py::keep_alive<1, 0>()); - m.def( - "free_function", [](Parent *, Child *) {}, py::keep_alive<1, 2>()); - m.def( - "invalid_arg_index", [] {}, py::keep_alive<0, 1>()); + m.def("free_function", [](Parent *, Child *) {}, py::keep_alive<1, 2>()); + m.def("invalid_arg_index", [] {}, py::keep_alive<0, 1>()); #if !defined(PYPY_VERSION) // test_alive_gc diff --git a/tests/test_class.cpp b/tests/test_class.cpp index 4a5c386f6d..c9313d2af9 100644 --- a/tests/test_class.cpp +++ b/tests/test_class.cpp @@ -475,8 +475,7 @@ TEST_SUBMODULE(class_, m) { py::class_(base, "Nested") .def(py::init<>()) .def("fn", [](Nested &, int, NestBase &, Nested &) {}) - .def( - "fa", [](Nested &, int, NestBase &, Nested &) {}, "a"_a, "b"_a, "c"_a); + .def("fa", [](Nested &, int, NestBase &, Nested &) {}, "a"_a, "b"_a, "c"_a); base.def("g", [](NestBase &, Nested &) {}); base.def("h", []() { return NestBase(); }); diff --git a/tests/test_copy_move.cpp b/tests/test_copy_move.cpp index f54733550a..4f93defe1f 100644 --- a/tests/test_copy_move.cpp +++ b/tests/test_copy_move.cpp @@ -289,8 +289,7 @@ TEST_SUBMODULE(copy_move_policies, m) { "get_moveissue1", [](int i) { return std::unique_ptr(new MoveIssue1(i)); }, py::return_value_policy::move); - m.def( - "get_moveissue2", [](int i) { return MoveIssue2(i); }, py::return_value_policy::move); + m.def("get_moveissue2", [](int i) { return MoveIssue2(i); }, py::return_value_policy::move); // Make sure that cast from pytype rvalue to other pytype works m.def("get_pytype_rvalue_castissue", [](double i) { return py::float_(i).cast(); }); diff --git a/tests/test_custom_type_casters.cpp b/tests/test_custom_type_casters.cpp index 3cbb8687fb..0ca2d25414 100644 --- a/tests/test_custom_type_casters.cpp +++ b/tests/test_custom_type_casters.cpp @@ -185,14 +185,10 @@ TEST_SUBMODULE(custom_type_casters, m) { py::arg_v(nullptr, ArgInspector1()).noconvert(true), py::arg() = ArgAlwaysConverts()); - m.def( - "floats_preferred", [](double f) { return 0.5 * f; }, "f"_a); - m.def( - "floats_only", [](double f) { return 0.5 * f; }, "f"_a.noconvert()); - m.def( - "ints_preferred", [](int i) { return i / 2; }, "i"_a); - m.def( - "ints_only", [](int i) { return i / 2; }, "i"_a.noconvert()); + m.def("floats_preferred", [](double f) { return 0.5 * f; }, "f"_a); + m.def("floats_only", [](double f) { return 0.5 * f; }, "f"_a.noconvert()); + m.def("ints_preferred", [](int i) { return i / 2; }, "i"_a); + m.def("ints_only", [](int i) { return i / 2; }, "i"_a.noconvert()); // test_custom_caster_destruction // Test that `take_ownership` works on types with a custom type caster when given a pointer diff --git a/tests/test_docstring_options.cpp b/tests/test_docstring_options.cpp index dda1cf6e41..de045a7ca1 100644 --- a/tests/test_docstring_options.cpp +++ b/tests/test_docstring_options.cpp @@ -15,37 +15,26 @@ TEST_SUBMODULE(docstring_options, m) { py::options options; options.disable_function_signatures(); - m.def( - "test_function1", [](int, int) {}, py::arg("a"), py::arg("b")); - m.def( - "test_function2", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); - - m.def( - "test_overloaded1", [](int) {}, py::arg("i"), "Overload docstring"); - m.def( - "test_overloaded1", [](double) {}, py::arg("d")); - - m.def( - "test_overloaded2", [](int) {}, py::arg("i"), "overload docstring 1"); - m.def( - "test_overloaded2", [](double) {}, py::arg("d"), "overload docstring 2"); - - m.def( - "test_overloaded3", [](int) {}, py::arg("i")); - m.def( - "test_overloaded3", [](double) {}, py::arg("d"), "Overload docstr"); + m.def("test_function1", [](int, int) {}, py::arg("a"), py::arg("b")); + m.def("test_function2", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); + + m.def("test_overloaded1", [](int) {}, py::arg("i"), "Overload docstring"); + m.def("test_overloaded1", [](double) {}, py::arg("d")); + + m.def("test_overloaded2", [](int) {}, py::arg("i"), "overload docstring 1"); + m.def("test_overloaded2", [](double) {}, py::arg("d"), "overload docstring 2"); + + m.def("test_overloaded3", [](int) {}, py::arg("i")); + m.def("test_overloaded3", [](double) {}, py::arg("d"), "Overload docstr"); options.enable_function_signatures(); - m.def( - "test_function3", [](int, int) {}, py::arg("a"), py::arg("b")); - m.def( - "test_function4", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); + m.def("test_function3", [](int, int) {}, py::arg("a"), py::arg("b")); + m.def("test_function4", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); options.disable_function_signatures().disable_user_defined_docstrings(); - m.def( - "test_function5", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); + m.def("test_function5", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); { py::options nested_options; @@ -59,8 +48,7 @@ TEST_SUBMODULE(docstring_options, m) { } } - m.def( - "test_function7", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); + m.def("test_function7", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); { py::options options; diff --git a/tests/test_eigen_matrix.cpp b/tests/test_eigen_matrix.cpp index 0c003d05e9..21261bfc2f 100644 --- a/tests/test_eigen_matrix.cpp +++ b/tests/test_eigen_matrix.cpp @@ -340,12 +340,10 @@ TEST_SUBMODULE(eigen_matrix, m) { if (have_numpy) { py::module_::import("numpy"); Eigen::Matrix defaultMatrix = Eigen::Matrix3d::Identity(); - m.def( - "defaults_mat", [](const Eigen::Matrix3d &) {}, py::arg("mat") = defaultMatrix); + m.def("defaults_mat", [](const Eigen::Matrix3d &) {}, py::arg("mat") = defaultMatrix); Eigen::VectorXd defaultVector = Eigen::VectorXd::Ones(32); - m.def( - "defaults_vec", [](const Eigen::VectorXd &) {}, py::arg("vec") = defaultMatrix); + m.def("defaults_vec", [](const Eigen::VectorXd &) {}, py::arg("vec") = defaultMatrix); } // test_sparse, test_sparse_signature m.def("sparse_r", [mat]() -> SparseMatrixR { diff --git a/tests/test_eigen_tensor.inl b/tests/test_eigen_tensor.inl index d864ce7379..25cf29f15b 100644 --- a/tests/test_eigen_tensor.inl +++ b/tests/test_eigen_tensor.inl @@ -121,8 +121,7 @@ void init_tensor_module(pybind11::module &m) { []() { return &get_fixed_tensor(); }, py::return_value_policy::copy); - m.def( - "copy_tensor", []() { return &get_tensor(); }, py::return_value_policy::copy); + m.def("copy_tensor", []() { return &get_tensor(); }, py::return_value_policy::copy); m.def( "copy_const_tensor", diff --git a/tests/test_iostream.py b/tests/test_iostream.py index d283eb1520..871269a92e 100644 --- a/tests/test_iostream.py +++ b/tests/test_iostream.py @@ -34,7 +34,7 @@ def test_captured_large_string(capsys): def test_captured_utf8_2byte_offset0(capsys): - msg = "\u07FF" + msg = "\u07ff" msg = "" + msg * (1024 // len(msg) + 1) m.captured_output_default(msg) @@ -44,7 +44,7 @@ def test_captured_utf8_2byte_offset0(capsys): def test_captured_utf8_2byte_offset1(capsys): - msg = "\u07FF" + msg = "\u07ff" msg = "1" + msg * (1024 // len(msg) + 1) m.captured_output_default(msg) @@ -54,7 +54,7 @@ def test_captured_utf8_2byte_offset1(capsys): def test_captured_utf8_3byte_offset0(capsys): - msg = "\uFFFF" + msg = "\uffff" msg = "" + msg * (1024 // len(msg) + 1) m.captured_output_default(msg) @@ -64,7 +64,7 @@ def test_captured_utf8_3byte_offset0(capsys): def test_captured_utf8_3byte_offset1(capsys): - msg = "\uFFFF" + msg = "\uffff" msg = "1" + msg * (1024 // len(msg) + 1) m.captured_output_default(msg) @@ -74,7 +74,7 @@ def test_captured_utf8_3byte_offset1(capsys): def test_captured_utf8_3byte_offset2(capsys): - msg = "\uFFFF" + msg = "\uffff" msg = "12" + msg * (1024 // len(msg) + 1) m.captured_output_default(msg) @@ -84,7 +84,7 @@ def test_captured_utf8_3byte_offset2(capsys): def test_captured_utf8_4byte_offset0(capsys): - msg = "\U0010FFFF" + msg = "\U0010ffff" msg = "" + msg * (1024 // len(msg) + 1) m.captured_output_default(msg) @@ -94,7 +94,7 @@ def test_captured_utf8_4byte_offset0(capsys): def test_captured_utf8_4byte_offset1(capsys): - msg = "\U0010FFFF" + msg = "\U0010ffff" msg = "1" + msg * (1024 // len(msg) + 1) m.captured_output_default(msg) @@ -104,7 +104,7 @@ def test_captured_utf8_4byte_offset1(capsys): def test_captured_utf8_4byte_offset2(capsys): - msg = "\U0010FFFF" + msg = "\U0010ffff" msg = "12" + msg * (1024 // len(msg) + 1) m.captured_output_default(msg) @@ -114,7 +114,7 @@ def test_captured_utf8_4byte_offset2(capsys): def test_captured_utf8_4byte_offset3(capsys): - msg = "\U0010FFFF" + msg = "\U0010ffff" msg = "123" + msg * (1024 // len(msg) + 1) m.captured_output_default(msg) diff --git a/tests/test_kwargs_and_defaults.cpp b/tests/test_kwargs_and_defaults.cpp index 9a12c42afa..2f40aca6af 100644 --- a/tests/test_kwargs_and_defaults.cpp +++ b/tests/test_kwargs_and_defaults.cpp @@ -22,8 +22,7 @@ TEST_SUBMODULE(kwargs_and_defaults, m) { m.def("kw_func0", kw_func); m.def("kw_func1", kw_func, py::arg("x"), py::arg("y")); m.def("kw_func2", kw_func, py::arg("x") = 100, py::arg("y") = 200); - m.def( - "kw_func3", [](const char *) {}, py::arg("data") = std::string("Hello world!")); + m.def("kw_func3", [](const char *) {}, py::arg("data") = std::string("Hello world!")); /* A fancier default argument */ std::vector list{{13, 17}}; @@ -79,14 +78,12 @@ TEST_SUBMODULE(kwargs_and_defaults, m) { "kw_lb_func5", [](const CustomRepr &) {}, py::arg("custom") = CustomRepr("array([[A, B],\r [C, D]])")); - m.def( - "kw_lb_func6", [](const CustomRepr &) {}, py::arg("custom") = CustomRepr(" \v\t ")); + m.def("kw_lb_func6", [](const CustomRepr &) {}, py::arg("custom") = CustomRepr(" \v\t ")); m.def( "kw_lb_func7", [](const std::string &) {}, py::arg("str_arg") = "First line.\n Second line."); - m.def( - "kw_lb_func8", [](const CustomRepr &) {}, py::arg("custom") = CustomRepr("")); + m.def("kw_lb_func8", [](const CustomRepr &) {}, py::arg("custom") = CustomRepr("")); // test_args_and_kwargs m.def("args_function", [](py::args args) -> py::tuple { @@ -279,11 +276,9 @@ TEST_SUBMODULE(kwargs_and_defaults, m) { // These should fail to compile: #ifdef PYBIND11_NEVER_DEFINED_EVER // argument annotations are required when using kw_only - m.def( - "bad_kw_only1", [](int) {}, py::kw_only()); + m.def("bad_kw_only1", [](int) {}, py::kw_only()); // can't specify both `py::kw_only` and a `py::args` argument - m.def( - "bad_kw_only2", [](int i, py::args) {}, py::kw_only(), "i"_a); + m.def("bad_kw_only2", [](int i, py::args) {}, py::kw_only(), "i"_a); #endif // test_function_signatures (along with most of the above) diff --git a/tests/test_methods_and_attributes.cpp b/tests/test_methods_and_attributes.cpp index c6faced577..c13ae933ed 100644 --- a/tests/test_methods_and_attributes.cpp +++ b/tests/test_methods_and_attributes.cpp @@ -374,8 +374,7 @@ TEST_SUBMODULE(methods_and_attributes, m) { m.def("overload_order", [](const std::string &) { return 1; }); m.def("overload_order", [](const std::string &) { return 2; }); m.def("overload_order", [](int) { return 3; }); - m.def( - "overload_order", [](int) { return 4; }, py::prepend{}); + m.def("overload_order", [](int) { return 4; }, py::prepend{}); #if !defined(PYPY_VERSION) // test_dynamic_attributes diff --git a/tests/test_numpy_array.cpp b/tests/test_numpy_array.cpp index 8c122a8658..c2f754208b 100644 --- a/tests/test_numpy_array.cpp +++ b/tests/test_numpy_array.cpp @@ -287,8 +287,7 @@ TEST_SUBMODULE(numpy_array, sm) { // [workaround(intel)] ICC 20/21 breaks with py::arg().stuff, using py::arg{}.stuff works. // Only accept the exact types: - sm.def( - "overloaded3", [](const py::array_t &) { return "int"; }, py::arg{}.noconvert()); + sm.def("overloaded3", [](const py::array_t &) { return "int"; }, py::arg{}.noconvert()); sm.def( "overloaded3", [](const py::array_t &) { return "double"; }, @@ -444,9 +443,8 @@ TEST_SUBMODULE(numpy_array, sm) { }); // resize to 3D array with each dimension = N - sm.def("array_resize3", [](py::array_t a, size_t N, bool refcheck) { - a.resize({N, N, N}, refcheck); - }); + sm.def("array_resize3", + [](py::array_t a, size_t N, bool refcheck) { a.resize({N, N, N}, refcheck); }); // test_array_create_and_resize // return 2D array with Nrows = Ncols = N @@ -460,9 +458,8 @@ TEST_SUBMODULE(numpy_array, sm) { sm.def("array_view", [](py::array_t a, const std::string &dtype) { return a.view(dtype); }); - sm.def("reshape_initializer_list", [](py::array_t a, size_t N, size_t M, size_t O) { - return a.reshape({N, M, O}); - }); + sm.def("reshape_initializer_list", + [](py::array_t a, size_t N, size_t M, size_t O) { return a.reshape({N, M, O}); }); sm.def("reshape_tuple", [](py::array_t a, const std::vector &new_shape) { return a.reshape(new_shape); }); @@ -471,8 +468,7 @@ TEST_SUBMODULE(numpy_array, sm) { [](const py::array &a) { return a[py::make_tuple(0, py::ellipsis(), 0)]; }); // test_argument_conversions - sm.def( - "accept_double", [](const py::array_t &) {}, py::arg("a")); + sm.def("accept_double", [](const py::array_t &) {}, py::arg("a")); sm.def( "accept_double_forcecast", [](const py::array_t &) {}, @@ -493,8 +489,7 @@ TEST_SUBMODULE(numpy_array, sm) { "accept_double_f_style_forcecast", [](const py::array_t &) {}, py::arg("a")); - sm.def( - "accept_double_noconvert", [](const py::array_t &) {}, "a"_a.noconvert()); + sm.def("accept_double_noconvert", [](const py::array_t &) {}, "a"_a.noconvert()); sm.def( "accept_double_forcecast_noconvert", [](const py::array_t &) {}, diff --git a/tests/test_numpy_dtypes.py b/tests/test_numpy_dtypes.py index e7854df4a6..790f63641c 100644 --- a/tests/test_numpy_dtypes.py +++ b/tests/test_numpy_dtypes.py @@ -77,9 +77,7 @@ def partial_nested_fmt(): partial_size = partial_ld_off + ld.itemsize partial_end_padding = partial_size % np.dtype("uint64").alignment partial_nested_size = partial_nested_off * 2 + partial_size + partial_end_padding - return "{{'names':['a'],'formats':[{}],'offsets':[{}],'itemsize':{}}}".format( - partial_dtype_fmt(), partial_nested_off, partial_nested_size - ) + return f"{{'names':['a'],'formats':[{partial_dtype_fmt()}],'offsets':[{partial_nested_off}],'itemsize':{partial_nested_size}}}" def assert_equal(actual, expected_data, expected_dtype): diff --git a/tests/test_stl.cpp b/tests/test_stl.cpp index ee75427c37..14ab685dfc 100644 --- a/tests/test_stl.cpp +++ b/tests/test_stl.cpp @@ -217,9 +217,8 @@ TEST_SUBMODULE(stl, m) { // NB: map and set keys are `const`, so while we technically do move them (as `const Type &&`), // casters don't typically do anything with that, which means they fall to the `const Type &` // caster. - m.def("cast_rv_map", []() { - return std::unordered_map{{"a", RValueCaster{}}}; - }); + m.def("cast_rv_map", + []() { return std::unordered_map{{"a", RValueCaster{}}}; }); m.def("cast_rv_nested", []() { std::vector>, 2>> v; v.emplace_back(); // add an array @@ -497,8 +496,7 @@ TEST_SUBMODULE(stl, m) { }); // test_stl_pass_by_pointer - m.def( - "stl_pass_by_pointer", [](std::vector *v) { return *v; }, "v"_a = nullptr); + m.def("stl_pass_by_pointer", [](std::vector *v) { return *v; }, "v"_a = nullptr); // #1258: pybind11/stl.h converts string to vector m.def("func_with_string_or_vector_string_arg_overload", diff --git a/tests/test_stl_binders.cpp b/tests/test_stl_binders.cpp index 96af9a4c4b..f846ae8482 100644 --- a/tests/test_stl_binders.cpp +++ b/tests/test_stl_binders.cpp @@ -270,7 +270,6 @@ TEST_SUBMODULE(stl_binders, m) { PYBIND11_NUMPY_DTYPE(VStruct, w, x, y, z); py::class_(m, "VStruct").def_readwrite("x", &VStruct::x); py::bind_vector>(m, "VectorStruct", py::buffer_protocol()); - m.def("get_vectorstruct", [] { - return std::vector{{false, 5, 3.0, true}, {true, 30, -1e4, false}}; - }); + m.def("get_vectorstruct", + [] { return std::vector{{false, 5, 3.0, true}, {true, 30, -1e4, false}}; }); } diff --git a/ubench/holder_comparison_extract_sheet_data.py b/ubench/holder_comparison_extract_sheet_data.py index 109d18e961..0676603066 100644 --- a/ubench/holder_comparison_extract_sheet_data.py +++ b/ubench/holder_comparison_extract_sheet_data.py @@ -4,7 +4,6 @@ # This code has no unit tests. # ruff cleanup deferred until the next time this code is actually used. - import sys from typing import List, Optional