from typing import Type
from typing import Set


def _all_subclasses_of(cls: Type) -> Set[Type]:
    """
    All subclasses of cls, including non-direct ones (child of child of ...).
    """
    direct_subclasses = set(cls.__subclasses__())
    return direct_subclasses.union(
        s for d in direct_subclasses for s in _all_subclasses_of(d)
    )