Skip to content

[BUG]: Default value for a callback function parameter causes incompatible function arguments error #5722

Open
@dbs4261

Description

@dbs4261

Required prerequisites

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions