pybind11/docs
Jason Rhinelander e7c9753f1d
feat: allow kw-only args after a py::args (#3402)
* Simply has_kw_only_args handling

This simplifies tracking the number of kw-only args by instead tracking
the number of positional arguments (which is really what we care about
everywhere this is used).

* Allow keyword-only arguments to follow py::args

This removes the constraint that py::args has to be last (or
second-last, with py::kwargs) and instead makes py::args imply
py::kw_only for any remaining arguments, allowing you to bind a function
that works the same way as a Python function such as:

    def f(a, *args, b):
        return a * b + sum(args)

    f(10, 1, 2, 3, b=20)  # == 206

With this change, you can bind such a function using:

    m.def("f", [](int a, py::args args, int b) { /* ... */ },
        "a"_a, "b"_a);

Or, to be more explicit about the keyword-only arguments:

    m.def("g", [](int a, py::args args, int b) { /* ... */ },
        "a"_a, py::kw_only{}, "b"_a);

(The only difference between the two is that the latter will fail at
binding time if the `kw_only{}` doesn't match the `py::args` position).

This doesn't affect backwards compatibility at all because, currently,
you can't have a py::args anywhere except the end/2nd-last.

* Take args/kwargs by const lvalue ref

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2021-10-28 23:16:55 -04:00
..
_static documentation improvements 2016-04-26 23:48:55 +02:00
advanced feat: allow kw-only args after a py::args (#3402) 2021-10-28 23:16:55 -04:00
cmake fix: find_import didn't work properly for classic tools (#2550) 2020-10-05 15:31:00 -04:00
basics.rst docs: add a note about compiling the example (#2737) 2020-12-24 09:51:36 -05:00
benchmark.py Add blacken-docs and pycln pre-commit hooks (#3292) 2021-09-22 15:38:50 -04:00
benchmark.rst ci: GHA basic format & pre-commit (#2309) 2020-07-20 13:35:21 -04:00
changelog.rst [skip ci] Tweaks in preparation for the 2.8.1 release. (#3421) 2021-10-27 14:35:10 -07:00
classes.rst Docs: Demonstrate non-enum internal types in example (#3314) 2021-09-30 14:45:06 -04:00
compiling.rst docs: fix minor typo (#3311) 2021-09-28 10:17:52 -04:00
conf.py Add blacken-docs and pycln pre-commit hooks (#3292) 2021-09-22 15:38:50 -04:00
Doxyfile feat: deprecate public constructors of module_ class (#2552) 2020-10-09 10:46:11 -04:00
faq.rst Add blacken-docs and pycln pre-commit hooks (#3292) 2021-09-22 15:38:50 -04:00
index.rst fix: chapters in PDF again (#2606) 2020-10-18 14:31:28 -04:00
installing.rst docs: add a note about compiling the example (#2737) 2020-12-24 09:51:36 -05:00
limitations.rst docs: reduce visibility of 3.9.0 warning (#3105) 2021-07-15 15:01:13 -04:00
Makefile took a stab at some documentation 2015-10-13 03:16:44 +02:00
pybind11_vs_boost_python1.png documentation improvements 2016-04-28 15:32:07 +02:00
pybind11_vs_boost_python1.svg Much more efficient generation of function signatures, updated docs 2016-01-17 22:31:15 +01:00
pybind11_vs_boost_python2.png documentation improvements 2016-04-28 15:32:07 +02:00
pybind11_vs_boost_python2.svg Much more efficient generation of function signatures, updated docs 2016-01-17 22:31:15 +01:00
pybind11-logo.png Very minor documentation fixes, updated logo 2016-01-17 22:31:15 +01:00
reference.rst feat: reapply fixed version of #3271 (#3293) 2021-09-23 15:06:07 -04:00
release.rst [skip ci] Tweaks in preparation for the 2.8.1 release. (#3421) 2021-10-27 14:35:10 -07:00
requirements.txt Fix: RTD Docutils Build (#3119) 2021-07-15 15:41:36 -04:00
upgrade.rst fix: deprecate make_simple_namespace, fix Python 3.11 (#3374) 2021-10-19 14:39:29 -04:00