[python-win32] "Casting" COM objects
Paul Prescod
paul@prescod.net
Wed, 02 Apr 2003 11:32:06 -0800
Consider the following case:
class A:
def foo(self): pass
class B(A):
def bar(self): pass
class C(A):
def car(self): pass
Now pretend Python had static typing:
class Z:
def __init__(self, thing):
self.thing = thing
def get_A() returns A:
return self.thing
Now in statically typed languages like C or IDL, it is perfectly legal
for C to return a "B" because a B isa A. Then, client code casts from an
A reference to a B reference to get access to the bar() function.
Now imagine the code above is the output of MakePy. The object returned
by MakePy is a B wrapped in a proxy for an A. What I would like to know
is whether there is a function out there that can take the _oleobj_
pointer and determine at runtime what the best proxy is for it. I've
figured out how to do some casting "manually" by importing a gen_py'd
module and selecting the right class, but I wonder if there is an easier way
Paul Prescod