Message171323
Since inheritance is more commonplace and more easily understood than __metaclass__, the abc module would benefit from a simple helper class:
class ABC(metaclass=ABCMeta):
pass
From a user's point-of-view, writing an abstract base call becomes simpler and clearer:
from abc import ABC, abstractmethod
class Vector(ABC):
@abstractmethod
def __iter__(self):
pass
def dot(self, other):
'Compute a dot product'
return sum(map(operator.mul, self, other))
Notice that this class seems less mysterious because it inherits from ABC rather than using __metaclass__=ABCMeta.
Also note, it has become a reasonably common practice for metaclass writers to put the __metaclass__ assignment in a class and have it get inherited rather than requiring users do the metaclass assignment themselves. |
|
Date |
User |
Action |
Args |
2012-09-25 23:20:31 | rhettinger | set | recipients:
+ rhettinger |
2012-09-25 23:20:31 | rhettinger | set | messageid: <1348615231.16.0.514985949274.issue16049@psf.upfronthosting.co.za> |
2012-09-25 23:20:10 | rhettinger | link | issue16049 messages |
2012-09-25 23:20:09 | rhettinger | create | |
|