[C++-sig] Loosing real python type in Python extend class
Alexandre Hamez
alexandre.hamez at gmail.com
Thu Mar 18 17:01:44 CET 2010
Hello,
If I have a (pure virtual) class foo that I expose in order to be extended in Python:
> struct foo_wrap
> : public foo
> , public wrapper<foo>
> {
>
> bool
> operator==( const foo& rhs )
> const
> {
> return this->get_override("__eq__")(rhs);
> }
>
> };
>
> BOOST_PYTHON_MODULE(module)
> {
>
> class_< foo_wrap >("Foo")
> .def("__eq__" , pure_virtual(&function<libsdd>::operator== ))
> ;
> }
Now in Python:
> class Bar(module.Foo):
>
> def __init__( self ):
> super(Bar,self).__init__()
>
> def __eq__(self,other):
> if not isinstance( other, Bar):
> # Always false!!!!
> return False
> else:
> # some test
If the 'other' parameter is given by the C++ side, then the type that __eq__ sees is 'module.Foo'.
Is there a way to give to the __eq__ method the real python type?
I suppose I can use a to_python_converter, but I'm not sure how to do this.
Thank you!
---------------------
Alexandre Hamez
More information about the Cplusplus-sig
mailing list