pybind11
pybind11 copied to clipboard
[BUG]: py::args can not be combined with kw_only(), triggers static assert
Required prerequisites
- [X] Make sure you've read the documentation. Your issue may be addressed there.
- [X] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- [X] Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
2.12.0
Problem description
I am defining a method that takes py::args and needs to also accept be able to keyword arguments
I don't want to accept just any keyword argument so I'm not using py::kwargs
The static assert seems to have a problem with this
Reproducible example code
m.def(
"project",
[](const py::object &df, const py::args &args, const string &groups) {
return true;
},
py::arg("df"), py::arg("args"), py::kw_only(), py::arg("kw1") = "");
lib/python3.12/site-packages/pybind11/include/pybind11/pybind11.h:261:9: error: static assertion failed due to requirement 'expected_num_args<pybind11::name, pybind11::scope, pybind11::sibling, pybind11::arg, pybind11::arg, pybind11::kw_only, pybind11::arg_v>(sizeof...(Args), argument_loader<const py::object &, const pybind11::args &, const std::string &>::args_pos >= 0, argument_loader<const py::object &, const pybind11::args &, const std::string &>::has_kwargs)': The number of argument annotations does not match the number of function arguments
static_assert(
^
lib/python3.12/site-packages/pybind11/include/pybind11/pybind11.h:145:9: note: in instantiation of function template specialization 'pybind11::cpp_function::initialize<(lambda at source.cpp:818:6), std::unique_ptr<duckdb::DuckDBPyRelation>, const py::object &, const pybind11::args &, const std::string &, pybind11::name, pybind11::scope, pybind11::sibling, pybind11::arg, pybind11::arg, pybind11::kw_only, pybind11::arg_v>' requested here
initialize(
^
lib/python3.12/site-packages/pybind11/include/pybind11/pybind11.h:1220:22: note: in instantiation of function template specialization 'pybind11::cpp_function::cpp_function<(lambda at source.cpp:818:6), pybind11::name, pybind11::scope, pybind11::sibling, pybind11::arg, pybind11::arg, pybind11::kw_only, pybind11::arg_v, void>' requested here
cpp_function func(std::forward<Func>(f),
^
source.cpp:816:4: note: in instantiation of function template specialization 'pybind11::module_::def<(lambda at source.cpp:818:6), pybind11::arg, pybind11::arg, pybind11::kw_only, pybind11::arg_v>' requested here
m.def(
^
### Is this a regression? Put the last known working version here if it is.
Not a regression