text_part_input.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. from collections.abc import Mapping
  2. from typing import TYPE_CHECKING, Any, Literal, TypeVar, Union, cast
  3. from attrs import define as _attrs_define
  4. from attrs import field as _attrs_field
  5. from ..types import UNSET, Unset
  6. if TYPE_CHECKING:
  7. from ..models.text_part_input_time import TextPartInputTime
  8. T = TypeVar("T", bound="TextPartInput")
  9. @_attrs_define
  10. class TextPartInput:
  11. """
  12. Attributes:
  13. type_ (Literal['text']):
  14. text (str):
  15. id (Union[Unset, str]):
  16. synthetic (Union[Unset, bool]):
  17. time (Union[Unset, TextPartInputTime]):
  18. """
  19. type_: Literal["text"]
  20. text: str
  21. id: Union[Unset, str] = UNSET
  22. synthetic: Union[Unset, bool] = UNSET
  23. time: Union[Unset, "TextPartInputTime"] = UNSET
  24. additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
  25. def to_dict(self) -> dict[str, Any]:
  26. type_ = self.type_
  27. text = self.text
  28. id = self.id
  29. synthetic = self.synthetic
  30. time: Union[Unset, dict[str, Any]] = UNSET
  31. if not isinstance(self.time, Unset):
  32. time = self.time.to_dict()
  33. field_dict: dict[str, Any] = {}
  34. field_dict.update(self.additional_properties)
  35. field_dict.update(
  36. {
  37. "type": type_,
  38. "text": text,
  39. }
  40. )
  41. if id is not UNSET:
  42. field_dict["id"] = id
  43. if synthetic is not UNSET:
  44. field_dict["synthetic"] = synthetic
  45. if time is not UNSET:
  46. field_dict["time"] = time
  47. return field_dict
  48. @classmethod
  49. def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
  50. from ..models.text_part_input_time import TextPartInputTime
  51. d = dict(src_dict)
  52. type_ = cast(Literal["text"], d.pop("type"))
  53. if type_ != "text":
  54. raise ValueError(f"type must match const 'text', got '{type_}'")
  55. text = d.pop("text")
  56. id = d.pop("id", UNSET)
  57. synthetic = d.pop("synthetic", UNSET)
  58. _time = d.pop("time", UNSET)
  59. time: Union[Unset, TextPartInputTime]
  60. if isinstance(_time, Unset):
  61. time = UNSET
  62. else:
  63. time = TextPartInputTime.from_dict(_time)
  64. text_part_input = cls(
  65. type_=type_,
  66. text=text,
  67. id=id,
  68. synthetic=synthetic,
  69. time=time,
  70. )
  71. text_part_input.additional_properties = d
  72. return text_part_input
  73. @property
  74. def additional_keys(self) -> list[str]:
  75. return list(self.additional_properties.keys())
  76. def __getitem__(self, key: str) -> Any:
  77. return self.additional_properties[key]
  78. def __setitem__(self, key: str, value: Any) -> None:
  79. self.additional_properties[key] = value
  80. def __delitem__(self, key: str) -> None:
  81. del self.additional_properties[key]
  82. def __contains__(self, key: str) -> bool:
  83. return key in self.additional_properties