def attributes_dict(self) -> dict[str, Any]:
    """Constructs a dictionary with all of the fields in the class.

    The result of this should be passable back to `from_attributes` to rebuild
    (a copy of) the object.

    Returns:
      A dictionary containing all of the dataclass fields of the object.
    """
    # `self` is guaranteed to be a dataclass by AbstractStructMetaclass
    assert dataclasses.is_dataclass(self)
    return {
        field.name: getattr(self, field.name)
        for field in dataclasses.fields(self)
    }
Constructs a dictionary with all of the fields in the class.

    The result of this should be passable back to `from_attributes` to rebuild
    (a copy of) the object.

    Returns:
      A dictionary containing all of the dataclass fields of the object.
    
penzai/core/struct.py