Abstract class

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Sep 14 15:50:30 EDT 2008


En Sun, 14 Sep 2008 16:15:04 -0300, Gary Herron  
<gherron at islandtraining.com> escribió:

> Please forget about Abstract Base Classes.  They have nothing to do with  
> what you want, and are a *HUGE* overkill for your application.   They  
> are not (yet) even part of standard Python, and are used primarily for a  
> class implementor to guarantee  to a user of a class that it provides a  
> specific interface.

Just to say that abstract classes *are* already available in Python 2.6:

Python 2.6rc1+ (trunk, Sep 13 2008, 11:29:39) [MSC v.1500 32 bit (Intel)]  
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import abc
>>> help(abc.abstractmethod)
Help on function abstractmethod in module abc:

abstractmethod(funcobj)
     A decorator indicating abstract methods.

     Requires that the metaclass is ABCMeta or derived from it.  A
     class that has a metaclass derived from ABCMeta cannot be
     instantiated unless all of its abstract methods are overridden.
     The abstract methods can be called using any of the the normal
     'super' call mechanisms.

     Usage:

         class C(metaclass=ABCMeta):
             @abstractmethod
             def my_abstract_method(self, ...):
                 ...

-- 
Gabriel Genellina




More information about the Python-list mailing list