[Python-3000] An introduction to ABC's

Emin.shopper Martinian.shopper emin.shopper at gmail.com
Tue Apr 24 16:39:45 CEST 2007

Dear Guido, Talin, and other Python Experts,

I would like to register my strong support/encouragement for some type of
abstract base class (ABC) mechanism in python. While I think dynamism,
reflection, duck-typing, unit tests, etc. are wonderful, I often come across
situations where ABCs are very useful.

For example, when writing programs which take a long time to run (e.g.,
numerical work or large simulations), it is very painful to run a unit test
that takes many minutes or even hours to run only to discover that a newly
defined class is missing a crucial method. By using ABCs appropriately, I
can make sure that all classes have the required methods as soon as a class
is imported instead of part-way through the simulation.

Below are links to the ABC implementation based on meta-classes and
decorators which I have been using for quite a while.


Some features of this module include:

  * Allows you to declare an ABC by inheriting from AbstractBaseClass.
  * Allows you to declare abstract methods using the @Abstract decorator.
  * Works with multiple inheritance (i.e., can inherit from multiple ABCs).
  * Allows you to turn off ABC checks on a per-class basis by setting
  * Allows partial ABCs (i.e., an ABC which inherits from another ABC but is
also abstract itself)
  * Relatively simple implementation (only a few hundred lines of pure
python including comments and doctests).
  * Documentation and doctests to illustrate/test features.

-Emin Martinian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20070424/d538d5be/attachment.html 

More information about the Python-3000 mailing list