Demonstrate that using the method of defining a class recommended on https://github.com/pybind/pybind11/issues/1193 does not allow for passing kwargs.

This commit is contained in:
Stu Hood 2024-10-10 10:30:14 -07:00
parent 7e418f4924
commit 35b16a8d5f
No known key found for this signature in database
GPG Key ID: A5D4B54D13ACCD3A
2 changed files with 20 additions and 0 deletions

View File

@ -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>

View File

@ -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)