Apply a plugin hook that may infer a more precise definition for a class.
(self, defn: ClassDef)
| 2160 | return False |
| 2161 | |
| 2162 | def apply_class_plugin_hooks(self, defn: ClassDef) -> None: |
| 2163 | """Apply a plugin hook that may infer a more precise definition for a class.""" |
| 2164 | |
| 2165 | for decorator in defn.decorators: |
| 2166 | decorator_name = self.get_fullname_for_hook(decorator) |
| 2167 | if decorator_name: |
| 2168 | hook = self.plugin.get_class_decorator_hook(decorator_name) |
| 2169 | # Special case: if the decorator is itself decorated with |
| 2170 | # typing.dataclass_transform, apply the hook for the dataclasses plugin |
| 2171 | # TODO: remove special casing here |
| 2172 | if hook is None and find_dataclass_transform_spec(decorator): |
| 2173 | hook = dataclasses_plugin.dataclass_tag_callback |
| 2174 | if hook: |
| 2175 | hook(ClassDefContext(defn, decorator, self)) |
| 2176 | |
| 2177 | if defn.metaclass: |
| 2178 | metaclass_name = self.get_fullname_for_hook(defn.metaclass) |
| 2179 | if metaclass_name: |
| 2180 | hook = self.plugin.get_metaclass_hook(metaclass_name) |
| 2181 | if hook: |
| 2182 | hook(ClassDefContext(defn, defn.metaclass, self)) |
| 2183 | |
| 2184 | for base_expr in defn.base_type_exprs: |
| 2185 | base_name = self.get_fullname_for_hook(base_expr) |
| 2186 | if base_name: |
| 2187 | hook = self.plugin.get_base_class_hook(base_name) |
| 2188 | if hook: |
| 2189 | hook(ClassDefContext(defn, base_expr, self)) |
| 2190 | |
| 2191 | # Check if the class definition itself triggers a dataclass transform (via a parent class/ |
| 2192 | # metaclass) |
| 2193 | spec = find_dataclass_transform_spec(defn) |
| 2194 | if spec is not None: |
| 2195 | dataclasses_plugin.add_dataclass_tag(defn.info) |
| 2196 | |
| 2197 | def get_fullname_for_hook(self, expr: Expression) -> str | None: |
| 2198 | if isinstance(expr, CallExpr): |
no test coverage detected