Attrs Instance

Functions:

is_attrs

is_attrs(obj)

Validates if an object is an attrs class or instance

Parameters:
  • obj (Any) –

    An object which will be checked to be an attrs class or instance

Returns:
  • bool

    Returns True if obj is an attrs class or instance

Source code in src/alpha/utils/is_attrs.py
def is_attrs(obj: Any) -> bool:
    """Validates if an object is an attrs class or instance

    Parameters
    ----------
    obj
        An object which will be checked to be an attrs class or instance

    Returns
    -------
    bool
        Returns True if obj is an attrs class or instance
    """
    cls = obj if isinstance(obj, type) else type(obj)
    return hasattr(cls, '__attrs_attrs__')