import types


def attributed_subclass(cls: type, name: str, **attributes):
    """
    Create a subclass of ``cls`` identical to the original,
    but with additional or redefined attributes

    :param cls: the class to be subclassed
    :param name: name of the new class
    :param attributes: new attributes
    :return: a subclass of ``cls``

    ::

        class Animal:
            pass  # implementation goes here

        Bird = attributed_subclass(Animal, 'Bird', wings=2)
        pelican = Bird()  # pelican.wings == 2

    .. note::
        Existence of ``__slots__``
        (and, consequently, the absence of the instance ``__dict__``)
        is preserved during subclassing
    """
    def set_subclass_attrs(ns):
        ns.update(attributes.items())
        if hasattr(cls, '__slots__'):
            ns['__slots__'] = ()  # no new instance attributes, so empty slots

    return types.new_class(name, (cls,), exec_body=set_subclass_attrs)