double foo(int x, int y, double dx, double dy) {...};
PYBIND11_MODULE(mymodule, m) {
m.doc() = "Module docstring";
m.def("foo", &foo, "Function docstring");
}
Once installed, the help pages don't include the positional argument name and instead replaced with arg<#>
:
>>> from mymodule import foo
>>> help(foo)
Help on built-in function foo in module mymodule:
foo(...) method of builtins.PyCapsule instance
foo(arg0: int, arg1: int, arg2: float, arg3: float) -> float
Function docstring
You need to pass their names. Here are two versions of how to do it:
using namespace pybind11::literals; // For _a
double foo(int x, int y, double dx, double dy) {...};
PYBIND11_MODULE(mymodule, m) {
m.doc() = "Module docstring";
// First version:
using namespace pybind11::literals;
m.def("foo", &foo, "Function docstring", "x"_a, "y"_a, "dx"_a, "dy"_a);
// Second version:
m.def("foo", &foo, "Function docstring", py::arg("x"), py::arg("y"), py::arg("dx"), py::arg("dy"));
}
The two versions are identical - the first one is syntactic sugar for the second one that uses user defined literals.