Skip to content

[python] Add support for keyword arguments

graeser requested to merge feature/python-add-kw-arg-support into master

This allows to pass keyword arguments to python callable objects. You can now e.g. use f(x,y, Python::arg("keyword", value)) or f(x,y, "keyword"_a=value) after using namespace Python::Literals.

  • This drops operator() implementations for fixed argument count in favour of a variadic template.
  • operator() now supports positional and keyword arguments.
  • Positional and keyword arguments can be mixed and will be filtered automatically.
  • The interface for passing keyword arguments basically follows the one in std::format.
  • The mechanism for implementing keyword arguments is actually independent of the python bindings and may be of interest in other places. It is zero cost in the sense that argument positions are evaluated statically and arguments can be forwarded perfectly.

Merge request reports