[Python-3000] Abilities / Interfaces
baptiste13 at altern.org
Thu Nov 23 00:15:18 CET 2006
Bill Janssen a écrit :
> I see nothing wrong with defining "empty" ABCs to indicate abilities
> rather than interfaces.
> class WellTested (Ability):
> """Indicates that the type has passed the QA process"""
> class TestedNumber (Number, WellTested):
And then if people want to add some tests to check if TestedNumber really
implements the Ability, they can do it using docstring syntax.
class WellTested (Ability):
"""Indicates that the type has passed the QA process
>>> hasattr(myinstance, 'attribute')
class TestedNumber (Number, WellTested):
The check_ability function would just call the doctest with the appropriate test
object (here a TestedNumber instance).
- mixin class has no behavior, hence no multiple inheritance problems
- doctest syntax allows to describe complex semantic properties without
reinventing an ad-hoc language like Zope interfaces do
- could be done already in python 2.X
- we need another mechanism for tagging instances. Perhaps a WeakKeyDictionary
mapping the instances to their added abilities can do.
More information about the Python-3000