MCPcopy
hub / github.com/python/mypy / _get_transform_spec

Function _get_transform_spec

mypy/plugins/dataclasses.py:973–990  ·  view source on GitHub ↗

Find the relevant transform parameters from the decorator/parent class/metaclass that triggered the dataclasses plugin. Although the resulting DataclassTransformSpec is based on the typing.dataclass_transform function, we also use it for traditional dataclasses.dataclass classes as well

(reason: Expression)

Source from the content-addressed store, hash-verified

971
972
973def _get_transform_spec(reason: Expression) -> DataclassTransformSpec:
974 """Find the relevant transform parameters from the decorator/parent class/metaclass that
975 triggered the dataclasses plugin.
976
977 Although the resulting DataclassTransformSpec is based on the typing.dataclass_transform
978 function, we also use it for traditional dataclasses.dataclass classes as well for simplicity.
979 In those cases, we return a default spec rather than one based on a call to
980 `typing.dataclass_transform`.
981 """
982 if _is_dataclasses_decorator(reason):
983 return _TRANSFORM_SPEC_FOR_DATACLASSES
984
985 spec = find_dataclass_transform_spec(reason)
986 assert spec is not None, (
987 "trying to find dataclass transform spec, but reason is neither dataclasses.dataclass nor "
988 "decorated with typing.dataclass_transform"
989 )
990 return spec
991
992
993def _is_dataclasses_decorator(node: Node) -> bool:

Callers 1

Calls 2

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…