Support keyword-only arguments (rebased)#2100
Conversation
|
+1 for this feature |
|
I'd love this as well! |
|
Ping: Are you planning on merging this soon? :) |
|
@gst - are there any updates to this? |
|
Pinging the creator of this PR @skoslowski |
|
@cpuhrsch, I am not a maintainer of pybind11, so there is nothing I can do. This PR only exists to help get the original code merged. I have been wanting this for a while now and it has dragged on for too long. So, for now, I have fallen back to using a private fork with this patch included. |
|
Mentioning @wjakob since this PR was approved a while ago and seems very useful in allowing pybind11 to further cover the python function-calling paradigm. |
|
This would be a great addition to pybind. Is there anyway this can be merged, @gst? |
|
I dont have merge privilege here otherwise I'd have already merged ;) @wjakob is the last person having done a commit 10 days ago.. ping ? |
|
I like this addition, but some minor bikeshedding: Thoughts on changing the tag to something shorter, perhaps m.def("f", [](int a, int b) { /* ... */ },
py::arg("a"), py::args_kw_only(), py::arg("b"));vs: m.def("f", [](int a, int b) { /* ... */ },
py::arg("a"), py::kwonly(), py::arg("b")); |
|
agree with you |
This adds support for a `py::args_kw_only()` annotation that can be
specified between `py::arg` annotations to indicate that any following
arguments are keyword-only. This allows you to write:
m.def("f", [](int a, int b) { /* ... */ },
py::arg("a"), py::args_kw_only(), py::arg("b"));
and have it work like Python 3's:
def f(a, *, b):
# ...
with respect to how `a` and `b` arguments are accepted (that is, `a` can
be positional or by keyword; `b` can only be specified by keyword).
|
I am also in favor of |
|
This is a nice feature, and the patch looks fantastic. Apologies that it's taken me a while to get to this. Many thanks to @jagerman and @skoslowski. |
|
Wow, didn't know this went in!!! |
This is a duplicate of #1196 rebased to current master resolving the merge conflicts on the existing PR.
(Fixes #1194)
This adds support for a
py::args_kw_only()annotation that can bespecified between
py::argannotations to indicate that any followingarguments are keyword-only. This allows you to write:
and have it work like Python 3's:
with respect to how
aandbarguments are accepted (that is,acanbe positional or by keyword;
bcan only be specified by keyword).