Engine for locating and statically inspecting expressions.
| 190 | |
| 191 | |
| 192 | class InspectionEngine: |
| 193 | """Engine for locating and statically inspecting expressions.""" |
| 194 | |
| 195 | def __init__( |
| 196 | self, |
| 197 | fg_manager: FineGrainedBuildManager, |
| 198 | *, |
| 199 | verbosity: int = 0, |
| 200 | limit: int = 0, |
| 201 | include_span: bool = False, |
| 202 | include_kind: bool = False, |
| 203 | include_object_attrs: bool = False, |
| 204 | union_attrs: bool = False, |
| 205 | force_reload: bool = False, |
| 206 | ) -> None: |
| 207 | self.fg_manager = fg_manager |
| 208 | self.verbosity = verbosity |
| 209 | self.limit = limit |
| 210 | self.include_span = include_span |
| 211 | self.include_kind = include_kind |
| 212 | self.include_object_attrs = include_object_attrs |
| 213 | self.union_attrs = union_attrs |
| 214 | self.force_reload = force_reload |
| 215 | # Module for which inspection was requested. |
| 216 | self.module: State | None = None |
| 217 | |
| 218 | def reload_module(self, state: State) -> None: |
| 219 | """Reload given module while temporary exporting types.""" |
| 220 | old = self.fg_manager.manager.options.export_types |
| 221 | self.fg_manager.manager.options.export_types = True |
| 222 | try: |
| 223 | self.fg_manager.flush_cache() |
| 224 | assert state.path is not None |
| 225 | self.fg_manager.update([(state.id, state.path)], []) |
| 226 | finally: |
| 227 | self.fg_manager.manager.options.export_types = old |
| 228 | |
| 229 | def expr_type(self, expression: Expression) -> tuple[str, bool]: |
| 230 | """Format type for an expression using current options. |
| 231 | |
| 232 | If type is known, second item returned is True. If type is not known, an error |
| 233 | message is returned instead, and second item returned is False. |
| 234 | """ |
| 235 | expr_type = self.fg_manager.manager.all_types.get(expression) |
| 236 | if expr_type is None: |
| 237 | return self.missing_type(expression), False |
| 238 | |
| 239 | type_str = format_type( |
| 240 | expr_type, self.fg_manager.manager.options, verbosity=self.verbosity |
| 241 | ) |
| 242 | return self.add_prefixes(type_str, expression), True |
| 243 | |
| 244 | def object_type(self) -> Instance: |
| 245 | builtins = self.fg_manager.graph["builtins"].tree |
| 246 | assert builtins is not None |
| 247 | object_node = builtins.names["object"].node |
| 248 | assert isinstance(object_node, TypeInfo) |
| 249 | return Instance(object_node, []) |
no outgoing calls
no test coverage detected
searching dependent graphs…