diff --git a/tests/test_class.cpp b/tests/test_class.cpp index 9001d86b1..109c85bf0 100644 --- a/tests/test_class.cpp +++ b/tests/test_class.cpp @@ -554,6 +554,22 @@ TEST_SUBMODULE(class_, m) { }); test_class::pr4220_tripped_over_this::bind_empty0(m); + + py::object parent_metaclass = py::reinterpret_borrow((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 diff --git a/tests/test_class.py b/tests/test_class.py index 9b2b1d834..a6aaa23cd 100644 --- a/tests/test_class.py +++ b/tests/test_class.py @@ -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)