Open
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
a2e59f0 # v2.13.6
Problem description
I should be able to provide a default value for a callable argument to a function, particularly because the type hint for a callable is actually an Optional[Callable[...]]
. Passing py::None
or nullptr
should act as that default value.
Reproducible example code
C++ library:
c++
PYBIND11_MODULE(test_library, m) {
m.def("temp", [](py::typing::Callable<void(py::int_)> callback) {
return;
}, py::arg_v("callback", py::none{}));
}
Python code:
python
import test_library
test_library.temp()
Error:
TypeError: temp(): incompatible function arguments. The following argument types are supported:
1. (callback: Callable[[int], None] = None) -> None
Is this a regression? Put the last known working version here if it is.
Not a regression