from typing import Iterable


def newclass(mcls=type, name="newclass", bases=(), **special):
    """Return a new class with the given metaclass, name and bases. Additional
    keyword arguments are added as class attributes wrapped in double
    underscores.

    Usage:
        A = newclass()
        B = newclass(name="B", init=lambda self: None)
        C = newclass(ABCMeta, "C", [A, B], doc="A new abstract class C")
    """
    if not isinstance(bases, Iterable):
        bases = (bases, )
    bases = tuple(bases)
    dct = {}
    for attr, val in special.items():
        if val is not None:
            dct['__'+attr+'__'] = val
    return mcls(name, bases, dct)