mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-21 20:55:11 +00:00
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:
parent
7e418f4924
commit
35b16a8d5f
@ -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>
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user