in content_api.py [0:0]
def get_dataclass(self, json_dataclass: type[T]) -> T:
"""Returns representation of the Part as a given dataclass.
Args:
json_dataclass: A dataclass that can be converted to/from JSON.
Returns:
The dataclass representation of the Part.
"""
if not mime_types.is_dataclass(self.mimetype):
raise ValueError('Part is not a dataclass.')
try:
# JSON conversions are provided by the dataclass_json decorator.
return json_dataclass.from_json(self.text) # pytype: disable=attribute-error
except AttributeError as e:
raise ValueError(
f'{json_dataclass.__name__} is not a valid json dataclass'
) from e