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:
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. ---------- components: Library (Lib) messages: 171323 nosy: rhettinger priority: normal severity: normal status: open title: Create abstract base classes by inheritance rather than a direct invocation of __metaclass__ versions: Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue16049> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com