Build a DataclassTransformSpec from the arguments passed to the given call to typing.dataclass_transform.
(self, call: CallExpr)
| 7937 | return self.modules[self.cur_mod_id].is_future_flag_set(flag) |
| 7938 | |
| 7939 | def parse_dataclass_transform_spec(self, call: CallExpr) -> DataclassTransformSpec: |
| 7940 | """Build a DataclassTransformSpec from the arguments passed to the given call to |
| 7941 | typing.dataclass_transform.""" |
| 7942 | parameters = DataclassTransformSpec() |
| 7943 | for name, value in zip(call.arg_names, call.args): |
| 7944 | # Skip any positional args. Note that any such args are invalid, but we can rely on |
| 7945 | # typeshed to enforce this and don't need an additional error here. |
| 7946 | if name is None: |
| 7947 | continue |
| 7948 | |
| 7949 | # field_specifiers is currently the only non-boolean argument; check for it first so |
| 7950 | # so the rest of the block can fail through to handling booleans |
| 7951 | if name == "field_specifiers": |
| 7952 | parameters.field_specifiers = self.parse_dataclass_transform_field_specifiers( |
| 7953 | value |
| 7954 | ) |
| 7955 | continue |
| 7956 | |
| 7957 | boolean = require_bool_literal_argument(self, value, name) |
| 7958 | if boolean is None: |
| 7959 | continue |
| 7960 | |
| 7961 | if name == "eq_default": |
| 7962 | parameters.eq_default = boolean |
| 7963 | elif name == "order_default": |
| 7964 | parameters.order_default = boolean |
| 7965 | elif name == "kw_only_default": |
| 7966 | parameters.kw_only_default = boolean |
| 7967 | elif name == "frozen_default": |
| 7968 | parameters.frozen_default = boolean |
| 7969 | else: |
| 7970 | self.fail(f'Unrecognized dataclass_transform parameter "{name}"', call) |
| 7971 | |
| 7972 | return parameters |
| 7973 | |
| 7974 | def parse_dataclass_transform_field_specifiers(self, arg: Expression) -> tuple[str, ...]: |
| 7975 | if not isinstance(arg, TupleExpr): |
no test coverage detected