Skip to content

Commit 35b16a8

Browse files
committed
Demonstrate that using the method of defining a class recommended on pybind#1193 does not allow for passing kwargs.
1 parent 7e418f4 commit 35b16a8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tests/test_class.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,22 @@ TEST_SUBMODULE(class_, m) {
554554
});
555555

556556
test_class::pr4220_tripped_over_this::bind_empty0(m);
557+
558+
py::object parent_metaclass = py::reinterpret_borrow<py::object>((PyObject *) &PyType_Type);
559+
py::dict attributes;
560+
561+
attributes["test"] = py::cpp_function(
562+
[](py::object self [[maybe_unused]], py::object x, py::object y) {
563+
py::print(x, y);
564+
return 0;
565+
},
566+
py::arg("x"),
567+
py::kw_only(),
568+
py::arg("y"),
569+
py::is_method(py::none())
570+
);
571+
572+
m.attr("KwOnlyMethod") = parent_metaclass("MwOnlyMethod", py::make_tuple(), attributes);
557573
}
558574

559575
template <int N>

tests/test_class.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,7 @@ def test_pr4220_tripped_over_this():
501501
m.Empty0().get_msg()
502502
== "This is really only meant to exercise successful compilation."
503503
)
504+
505+
506+
def test_kw_only():
507+
assert (m.KwOnlyMethod().test("x", y="y") == 0)

0 commit comments

Comments
 (0)