Skip to content

Implicit conversion issue with None #642

@mdcb

Description

@mdcb

Here's a minimal test-case to illustrate the issue:

struct Any {
    Any(py::object & obj) {}
};

void foo (Any & obj) {}

...

py::class_<Any>(m, "Any")
    .def(py::init<py::object>());

m.def("foo", &foo);

py::implicitly_convertible<py::object, Any>();

This results in:

>>> foo(123) # ok
>>> foo('')  # ok
>>> foo([])  # ok
>>> foo({})  # ok
>>> foo(None)
TypeError: foo(): incompatible function arguments. The following argument types are supported:
    1. (arg0: test.Any) -> None

Invoked with: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions