Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Oct 5, 2024
1 parent 8cf1cdb commit 9d107d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -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...>();

Expand Down
7 changes: 4 additions & 3 deletions tests/test_kwargs_and_defaults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
}
10 changes: 8 additions & 2 deletions tests/test_kwargs_and_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit 9d107d2

Please sign in to comment.