You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Override deduced Base class when defining Derived methods
When defining method from a member function pointer (e.g. `.def("f",
&Derived::f)`) we run into a problem if `&Derived::f` is actually
implemented in some base class `Base` when `Base` isn't
pybind-registered.
This happens because the class type is deduced, which then becomes a
lambda with first argument this deduced type. For a base class
implementation, the deduced type is `Base`, not `Derived`, and so we
generate and registered an overload which takes a `Base *` as first
argument. Trying to call this fails if `Base` isn't registered (e.g.
because it's an implementation detail class that isn't intended to be
exposed to Python) because the type caster for an unregistered type
always fails.
This commit extends the pybind11::is_method annotation into a templated
annotation containing the class being registered, which we can then
extract to override the first argument to the derived type when
attempting to register a base class method for a derived class.
This also slightly simplifies def_readwrite/def_readonly, which can rely
on def_property to wrap their lambdas into cpp_functions with the
appropriate rvp.
0 commit comments