abc – Abstract Base Class Enhancements

The abc module extends Python’s built-in abc module with a few additional operations. For convenience, this module re-exports the bindings from the built-in abc.

>>> from md.abc import *

Decorators

registers(*subclasses) → decorator

A class decorator for declaring that the ABC being defined is already implemented by subclasses. This is a shortcut for calling the register() method repeatedly.

>>> from numbers import Number

>>> @registers(type(None), basestring, Number, tuple)
... class Immutable(object):
...      __metaclass__ = ABCMeta

>>> issubclass(tuple, Immutable)
True
implements(*abc) → decorator

A class decorator declaring that the class being defined implements one or more ABCs. This is useful when you want to register a new concrete class with an ABC, but don’t want to inherit from it directly.

>>> class SpecialType(type):
...     ## Custom logic here
...     pass

>>> @implements(Immutable)
... class special(object):
...     __metaclass__ = SpecialType

>>> issubclass(special, Immutable)
True

Table Of Contents

Previous topic

Reference

Next topic

expect – Primitive Type Expectations

This Page