[C++-sig] Python + Boost Python V2 + downcasting

David Abrahams dave at boost-consulting.com
Thu Nov 7 16:17:24 CET 2002


I wrote:

> Let's look for other solutions; I just don't think 'isinstance' is
> appropriate. You see, Python really is handling a class called 'Base',
> even when the pointer actually refers to a 'Derived', and Python's
> isinstance just crawls up the Python class hierarchy to find the class
> you're looking for.

<snip>

> Ultimately, I think the best solution is going to be to add a new kind
> of ReturnValuePolicy which uses typeid() on the pointer to get the
> most-derived class, looks up the corresponding Python class in the
> converter::registry, and builds a pointer_holder around it using the
> appropriate Python class type. Hmm, looking carefully, this might not
> require a new ReturnValuePolicy, and could be as simple as making some
> judicious changes to boost/python/object/make_instance.hpp.**

In case it wasn't clear, the above change, if I can figure out how to
do it, would make isinstance() work as you expect.

-Dave

-- 
                    David Abrahams
dave at boost-consulting.com * http://www.boost-consulting.com





More information about the Cplusplus-sig mailing list