[PEAK] dispatch.add_assignment_advisor

Thomas Heller theller at python.net
Fri Dec 3 15:19:19 EST 2004


[Repost - the first one is still in the list-admin's queue because I
wasn't subscribed, sorry for that]

Only for fun, I'm experimenting with dispatch.add_assignment_advisor and
sick decorators.

The cool thing is that it also works with Python 2.3, and that it also
is able to decorate classes (much more convenient than metaclasses,
especially for multiple inheritence, where very soon metaclass conficts
arise).

Unfortunately, the experiment didn't go as smooth as I first expected.
Consider this code (cominterface and commethod are 'decorators' which
call add_assignment_advisor (the correct term would probably be 'which
add an assignment advisor):

cominterface(uuid = "{00000000-0000-0000-C000-000000000046}")
class IUnknown(object):

    commethod(index=1,
              restype = HRESULT,
              argtypes = [POINTER(GUID), POINTER(c_void_p)])
    def QueryInterface(self, interface):
        "Query for another interface"

    commethod(index=2, restype=c_long)
    def AddRef(self):
        "Increase the reference count"

    commethod(index=1, restype=c_long)
    def Release(self):
        "Decrease the reference count"

The problem is that the IUnknown methods are created first, and the
commethod decorator is called.
After that, the IUnknown type itself is created, and I expected that the
cominterface decorator would be called - but it isn't.
Any idea how to make this work as expected?

Thanks,

Thomas





More information about the PEAK mailing list