CONSTRUCT - Python's way of Ruby's "alias_method"
maric at aristote.info
Thu Jun 8 15:55:54 CEST 2006
Le Jeudi 08 Juin 2006 15:15, Duncan Booth a écrit :
> but the more usual way is just to call the original method directly in the
> base class.
> class SqliteAdapter(BaseClass):
> def create_table(self, *args)
> result = BaseClass.create_table(self, *args)
> return result
Yeah, this the right way to reuse ancestor's implementation of a method.
> If that isn't what you are trying to achieve you'll have to explain more.
I'm not a ruby programmer, but I understood it like this : the prupose is to
modify the behavior of an existing third-party class, in all application
(even in existing third party modules), without any code modifications
(traditional patch) in those modules.
Your proposal is not as good here, assuming BaseClass is defined in module
toto, you can still do toto.BaseClass = SqliteAdapter, but you must ensure
that this code is imported before any other where classes inherit from
BaseClass. The one I porpose in my other post is robust, several packages can
even patch the same method with no side effects.
Aristote - www.aristote.info
3 place des tapis
Tel: +33 426 880 097
More information about the Python-list