Open YannickJadoul opened 4 years ago
A mildly related change that I've ran into -- having virtual functions that have different python signatures from the C++ signature. Take for example:
getDescription(std::ostream &os) override;
In this case, I want the python API to be:
getDescription() -> str
But still be interoperable from C++. I have some modifications of the OVERRIDE macros in robotpy-build if there's interest in tackling this problem upstream.
@virtuald For that, we do have py::get_override
, I guess, to roll your own? But yes, true, it's related. How horrible macros are, is also related :-/
Issue description
The
PYBIND11_OVERRIDE
macros don't allow for thereturn_value_policy
to be specified. It is alwaysobject_api<T>::operator ()
's default,automatic_reference
. This results in problems when trying to nót copy a C++ object that doesn't have a Python object associated yet.@davidelbaze bumped into this issue on Gitter, and I debugged and tracked the solution down to this issue.
Reproducible example code
@davidelbaze's original code:
So, it seems like we 1. need to add a warning to the docs about the default
return_value_policy
, but it would also be nice to avoid a way to specify thereturn_value_policy
. Better ideas than adding 4 morePYBIND11_OVERRIDE
macro variants are welcome. I can create the PR, obviously, but I'd first like to discuss how to best solve this.