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)
| 971 | |
| 972 | |
| 973 | def _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 | |
| 993 | def _is_dataclasses_decorator(node: Node) -> bool: |
no test coverage detected
searching dependent graphs…