[New-bugs-announce] [issue16049] Create abstract base classes by inheritance rather than a direct invocation of __metaclass__
report at bugs.python.org
Wed Sep 26 01:20:31 CEST 2012
New submission from Raymond Hettinger:
Since inheritance is more commonplace and more easily understood than __metaclass__, the abc module would benefit from a simple helper class:
>From a user's point-of-view, writing an abstract base call becomes simpler and clearer:
from abc import ABC, abstractmethod
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.
components: Library (Lib)
title: Create abstract base classes by inheritance rather than a direct invocation of __metaclass__
versions: Python 3.4
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce