def subclasses(cls):
    """List all subclasses of cls recursively."""
    p = {cls}
    subclasses = set()
    while p:
        subclasses.update(p)
        q = set()
        for base in p:
            for subclass in type.__subclasses__(base):
                if subclass not in subclasses:
                    q.add(subclass)
        p = q
    return subclasses