Abstract Classes

Utilities to deal with abstract base classes and virtual subclasses.

New in version 0.2.

class brownie.abstract.ABCMeta[source]

On Python 2.6 this class is actually abc.ABCMeta, on versions lower than that it’s simply a dummy. Which makes implementing abstract classes easier if you want to support Python versions which don’t support class.__subclasscheck__() and class.__instancecheck__().

class brownie.abstract.VirtualSubclassMeta(name, bases, attributes)[source]

A metaclass which allows you to easily define abstract super classes, simply inherit from this metaclass and set the virtual_superclasses attribute to an iterable:

>>> from brownie.abstract import ABCMeta, VirtualSubclassMeta
>>>
>>> class VirtualBaseClass(object):
...     __metaclass__ = ABCMeta
>>>
>>> class VirtualSubclass(object):
...     __metaclass__ = VirtualSubclassMeta
...
...     virtual_superclasses = (VirtualBaseClass, )
>>>
>>> issubclass(VirtualSubclass, VirtualBaseClass)
True
class brownie.abstract.AbstractClassMeta(name, bases, attributes)[source]

A metaclass for abstract base classes which are also virtual subclasses.

Simply set virtual_subclasses to an iterable of classes your class is supposed to virtually inherit from:

>>> from brownie.abstract import ABCMeta, AbstractClassMeta, \
...                              VirtualSubclassMeta
>>> class Foo(object):
...     __metaclass__ = ABCMeta
>>>
>>> class Bar(object):
...     __metaclass__ = AbstractClassMeta
...
...     virtual_superclasses = (Foo, )
>>>
>>> class Baz(object):
...     __metaclass__ = VirtualSubclassMeta
...
...     virtual_superclasses = (Bar, )
>>>
>>> issubclass(Baz, Foo)
True
>>> issubclass(Baz, Bar)
True

Note

All classes could use AbstractClassMeta as __metaclass__ and the result would be the same, the usage here is just to demonstrate the specific problem which is solved.

Navigation

Documentation overview

This Page

Fork me on GitHub