MCPcopy Index your code
hub / github.com/python/mypy / DataclassTransformSpec

Class DataclassTransformSpec

mypy/nodes.py:5129–5197  ·  view source on GitHub ↗

Specifies how a dataclass-like transform should be applied. The fields here are based on the parameters accepted by `typing.dataclass_transform`.

Source from the content-addressed store, hash-verified

5127
5128
5129class DataclassTransformSpec:
5130 """Specifies how a dataclass-like transform should be applied. The fields here are based on the
5131 parameters accepted by `typing.dataclass_transform`."""
5132
5133 __slots__ = (
5134 "eq_default",
5135 "order_default",
5136 "kw_only_default",
5137 "frozen_default",
5138 "field_specifiers",
5139 )
5140
5141 def __init__(
5142 self,
5143 *,
5144 eq_default: bool | None = None,
5145 order_default: bool | None = None,
5146 kw_only_default: bool | None = None,
5147 field_specifiers: tuple[str, ...] | None = None,
5148 # Specified outside of PEP 681:
5149 # frozen_default was added to CPythonin https://github.com/python/cpython/pull/99958 citing
5150 # positive discussion in typing-sig
5151 frozen_default: bool | None = None,
5152 ) -> None:
5153 self.eq_default = eq_default if eq_default is not None else True
5154 self.order_default = order_default if order_default is not None else False
5155 self.kw_only_default = kw_only_default if kw_only_default is not None else False
5156 self.frozen_default = frozen_default if frozen_default is not None else False
5157 self.field_specifiers = field_specifiers if field_specifiers is not None else ()
5158
5159 def serialize(self) -> JsonDict:
5160 return {
5161 "eq_default": self.eq_default,
5162 "order_default": self.order_default,
5163 "kw_only_default": self.kw_only_default,
5164 "frozen_default": self.frozen_default,
5165 "field_specifiers": list(self.field_specifiers),
5166 }
5167
5168 @classmethod
5169 def deserialize(cls, data: JsonDict) -> DataclassTransformSpec:
5170 return DataclassTransformSpec(
5171 eq_default=data.get("eq_default"),
5172 order_default=data.get("order_default"),
5173 kw_only_default=data.get("kw_only_default"),
5174 frozen_default=data.get("frozen_default"),
5175 field_specifiers=tuple(data.get("field_specifiers", [])),
5176 )
5177
5178 def write(self, data: WriteBuffer) -> None:
5179 write_tag(data, DT_SPEC)
5180 write_bool(data, self.eq_default)
5181 write_bool(data, self.order_default)
5182 write_bool(data, self.kw_only_default)
5183 write_bool(data, self.frozen_default)
5184 write_str_list(data, self.field_specifiers)
5185 write_tag(data, END_TAG)
5186

Callers 4

dataclasses.pyFile · 0.90
deserializeMethod · 0.85
readMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…