subclassing extension type and assignment to __class__

David Bolen db3l at
Tue Nov 30 01:23:43 CET 2004

gregory lielens <gregory.lielens at> writes:

> Yes I was affraid this would be the conclusion: embedding instead of
> inheritance...But this means that not only the method that need to be
> modified need to be rewritten in python, all the other ones also just
> to delegate to the embedded instance...
> This is not too practical, even if such writing can be more or less
> automatized...

Unless I'm misunderstanding, couldn't one of __getattr__ or
__getattribute__ make mapping other methods you don't override very
simple and practical, not to mention fully automated with 2-3 lines of
code?  In particular, __getattr__ would seem good for your use since
it is only called for attributes that couldn't already be located.

I've had code that wrapped underlying objects in a number of cases, and
always found that to be a pretty robust mechanism.

-- David

More information about the Python-list mailing list