Add bases to class (late subclassing)

    Annoyingly we cannot yet modify __bases__ of an existing
    class, instead we must create another subclass, see here;
    http://bugs.python.org/issue672115

    >>> class A(object): pass
    >>> class B(object): pass
    >>> class C(object): pass
    >>> issubclass(B, A)
    False
    >>> D = subclass(B, A)
    >>> issubclass(D, A)
    True
    >>> issubclass(D, B)
    True

def subclass(cls, *bases, **kwargs):
    """
    Add bases to class (late subclassing)

    Annoyingly we cannot yet modify __bases__ of an existing
    class, instead we must create another subclass, see here;
    http://bugs.python.org/issue672115

    >>> class A(object): pass
    >>> class B(object): pass
    >>> class C(object): pass
    >>> issubclass(B, A)
    False
    >>> D = subclass(B, A)
    >>> issubclass(D, A)
    True
    >>> issubclass(D, B)
    True
    """
    last = kwargs.get('last', False)
    bases = tuple(bases)
    for base in bases:
        assert inspect.isclass(base), "bases must be classes"
    new_bases = (cls,)+bases if last else bases+(cls,)
    new_cls = type(cls.__name__, tuple(new_bases), {})
    return new_cls