Message171323
| Author |
rhettinger |
| Recipients |
rhettinger |
| Date |
2012年09月25日.23:20:09 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1348615231.16.0.514985949274.issue16049@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| 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 |
|