def default_representer()

in src/databao_context_engine/serialisation/yaml.py [0:0]


def default_representer(dumper: SafeDumper, data: object) -> Node:
    if isinstance(data, Mapping):
        return dumper.represent_dict(data)
    elif hasattr(data, "__dict__"):
        # Doesn't serialise "private" attributes (that starts with an _)
        data_public_attributes = {key: value for key, value in data.__dict__.items() if not key.startswith("_")}
        if data_public_attributes:
            return dumper.represent_dict(data_public_attributes)
        else:
            # If there is no public attributes, we default to the string representation
            return dumper.represent_str(str(data))
    else:
        return dumper.represent_str(str(data))