Transfer undefined class methods to attribute's method.

Diez B. Roggisch nospam-deets at web.de
Mon Feb 9 09:34:21 EST 2004


> Maybe I was a little too detailed in my previous post [same title]. I can
> boil down my problem to this: say I have a class A that I encapsulate with
> a class Proxy. Now I just want to override and add some functionality (see
> my other post why). All functionality not defined in the Proxy class
> should be delegated (I can't use inheritance, see other post). It should
> be possible to achieve this using Python's great introspection
> possibilities, but I can't find out how. Any help would be really
> appreciated!

Why don't you just scan the underlying object for all methods it has (using
the objects __dict__, filtering with type method) and add these methods on
your proxy when there exists no method of the same name (using the proyies
dict)? That would eliminate the need of a general-purpose method call
interception and do what you want.

I'm a little bit too lazy right now create a working example, but I think
you should be able to come up with your own in no time - if not, ask again
(and someone more enlightened might answer, or I get down on my a** and
write something... :))

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list