Skip to content

Commit

Permalink
Demonstrate that using the method of defining a class recommended on p…
Browse files Browse the repository at this point in the history
…ybind#1193 does not allow for passing kwargs.
  • Loading branch information
stuhood committed Oct 10, 2024
1 parent 7e418f4 commit 35b16a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,22 @@ TEST_SUBMODULE(class_, m) {
});

test_class::pr4220_tripped_over_this::bind_empty0(m);

py::object parent_metaclass = py::reinterpret_borrow<py::object>((PyObject *) &PyType_Type);
py::dict attributes;

attributes["test"] = py::cpp_function(
[](py::object self [[maybe_unused]], py::object x, py::object y) {
py::print(x, y);
return 0;
},
py::arg("x"),
py::kw_only(),
py::arg("y"),
py::is_method(py::none())
);

m.attr("KwOnlyMethod") = parent_metaclass("MwOnlyMethod", py::make_tuple(), attributes);
}

template <int N>
Expand Down
4 changes: 4 additions & 0 deletions tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,7 @@ def test_pr4220_tripped_over_this():
m.Empty0().get_msg()
== "This is really only meant to exercise successful compilation."
)


def test_kw_only():
assert (m.KwOnlyMethod().test("x", y="y") == 0)

0 comments on commit 35b16a8

Please sign in to comment.