(original) (raw)
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.
http://mail.python.org/pipermail/python-list/2006-December/419941.html
http://alum.mit.edu/www/emin/source_code/py_abc/abc.py
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 klass.__allow_abstract__=True.
* 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.
Sincerely,
-Emin Martinian