style: pre-commit fixes

This commit is contained in:
pre-commit-ci[bot] 2024-10-05 13:45:38 +00:00
parent 8cf1cdbc96
commit 9d107d2f75
3 changed files with 16 additions and 7 deletions

View File

@ -1570,9 +1570,11 @@ class argument_loader {
using indices = make_index_sequence<sizeof...(Args)>;
template <typename Arg>
using argument_is_args = all_of<std::is_base_of<args, intrinsic_t<Arg>>, negation<std::is_pointer<Arg>>>;
using argument_is_args
= all_of<std::is_base_of<args, intrinsic_t<Arg>>, negation<std::is_pointer<Arg>>>;
template <typename Arg>
using argument_is_kwargs = all_of<std::is_base_of<kwargs, intrinsic_t<Arg>>, negation<std::is_pointer<Arg>>>;
using argument_is_kwargs
= all_of<std::is_base_of<kwargs, intrinsic_t<Arg>>, negation<std::is_pointer<Arg>>>;
// Get kwargs argument position, or -1 if not present:
static constexpr auto kwargs_pos = constexpr_last<argument_is_kwargs, Args...>();

View File

@ -60,7 +60,7 @@ struct handle_type_name<KWArgsSubclass> {
};
template <>
struct type_caster<MoveOrCopyInt> {
PYBIND11_TYPE_CASTER(MoveOrCopyInt*, const_name("MoveOrCopyInt"));
PYBIND11_TYPE_CASTER(MoveOrCopyInt *, const_name("MoveOrCopyInt"));
bool load(handle src, bool) {
auto as_class = MoveOrCopyInt(src.cast<int>());
value = &as_class;
@ -389,9 +389,10 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
return py::make_tuple(args, kwargs);
});
// Test that support for args and kwargs subclasses skips checking arguments passed in as pointers
// Test that support for args and kwargs subclasses skips checking arguments passed in as
// pointers
m.def("args_kwargs_subclass_function_with_pointer_arg",
[](MoveOrCopyInt* pointer, const ArgsSubclass &args, const KWArgsSubclass &kwargs) {
[](MoveOrCopyInt *pointer, const ArgsSubclass &args, const KWArgsSubclass &kwargs) {
return py::make_tuple(pointer->value, args, kwargs);
});
}

View File

@ -107,7 +107,11 @@ def test_arg_and_kwargs():
kwargs = {"arg3": "a3", "arg4": 4}
assert m.args_kwargs_function(*args, **kwargs) == (args, kwargs)
assert m.args_kwargs_subclass_function(*args, **kwargs) == (args, kwargs)
assert m.args_kwargs_subclass_function_with_pointer_arg(10, *args, **kwargs) == (10, args, kwargs)
assert m.args_kwargs_subclass_function_with_pointer_arg(10, *args, **kwargs) == (
10,
args,
kwargs,
)
def test_mixed_args_and_kwargs(msg):
@ -429,7 +433,9 @@ def test_args_refcount():
)
assert refcount(myval) == expected
assert m.args_kwargs_subclass_function_with_pointer_arg(7, 8, myval, a=1, b=myval) == (
assert m.args_kwargs_subclass_function_with_pointer_arg(
7, 8, myval, a=1, b=myval
) == (
7,
(8, myval),
{"a": 1, "b": myval},