CoolFace
Apppublic

Backup-bdg/OpenHands

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
utils.py21 linesDownload Raw Back to serialization
1def remove_fields(obj: dict | list | tuple, fields: set[str]) -> None:2    """Remove fields from an object.3 4    Parameters:5    - obj: The dictionary, or list of dictionaries to remove fields from6    - fields (set[str]): A set of field names to remove from the object7    """8    if isinstance(obj, dict):9        for field in fields:10            if field in obj:11                del obj[field]12        for _, value in obj.items():13            remove_fields(value, fields)14    elif isinstance(obj, (list, tuple)):15        for item in obj:16            remove_fields(item, fields)17    if hasattr(obj, '__dataclass_fields__'):18        raise ValueError(19            'Object must not contain dataclass, consider converting to dict first'20        )21