Class/type unification and reference to unbound methods

Christian Tanzer tanzer at tttech.com
Fri May 11 05:47:33 EDT 2001


The python-dev summary  of traffic between Apr 26 and May 9
(inclusive) 2001 contains the snippet:

   The long term solution is to change the syntax for getting - or
   removing entirely - unbound methods.  As far as anyone can make out,
   all that unbound methods are used for is called superclasses' methods
   from overriding methods, so if one can find another way of spelling
   that, then removing unbound methods entirely could be contemplated.

Please, please, don't assume that unbound methods are only used for
chaining up in the inheritance hierarchy. 

I sometimes refer to superclasses' methods in the class body as in:

   class A:
     def spam(self):
       ...

   class B(A):
     def spam(self):
       ...

   class C(A):
     def spam(self):
       ...
   
   class D(B, C):
     spam = C.spam

This is akin to feature renaming as supported by Eiffel and comes in
handy when one class is found in the inheritance chain repeatedly.
Such renaming also is useful with extensive use of mixins.

Access to unbound methods is also useful if one wants to
change the implementation of a specific method of a class. I sometimes
use this idiom to change a method of a reusable class to add some
application specific functionality to that method. If the class sits
high up in the inheritance hierarchy, replacing the unbound method by
another one (which might or might not call the original method
internally) is the most convenient way for doing this (even if it is
not in the books).

-- 
Christian Tanzer                                          tanzer at tttech.com
TTTech Computertechnik AG,  Schoenbrunnerstrasse 7,  A-1040 Vienna, Austria
Voice: +43 1 585 34 34 22, Fax: +43 1 585 34 34 90,  http://www.tttech.com/




More information about the Python-list mailing list