Module enrgdaq.utils.subclasses
Functions
def all_subclasses(cls: type) ‑> set[type]-
Expand source code
def all_subclasses(cls: type) -> set[type]: """ Returns a set of all subclasses of a given class, ensuring that modules in the same top-level package are imported so all subclasses are found. Args: cls (type): The class to get subclasses of. Returns: set[type]: A set of all subclasses of the given class. """ if hasattr(cls, "__module__") and cls.__module__: top_pkg = cls.__module__.split(".")[0] _ensure_modules_imported(top_pkg) return set(cls.__subclasses__()).union( [s for c in cls.__subclasses__() for s in all_subclasses(c)] )Returns a set of all subclasses of a given class, ensuring that modules in the same top-level package are imported so all subclasses are found.
Args
cls:type- The class to get subclasses of.
Returns
set[type]- A set of all subclasses of the given class.