| 369 | |
| 370 | |
| 371 | class ASTConverter: |
| 372 | def __init__( |
| 373 | self, |
| 374 | options: Options, |
| 375 | is_stub: bool, |
| 376 | errors: Errors, |
| 377 | *, |
| 378 | strip_function_bodies: bool, |
| 379 | path: str, |
| 380 | ) -> None: |
| 381 | # 'C' for class, 'D' for function signature, 'F' for function, 'L' for lambda |
| 382 | self.class_and_function_stack: list[Literal["C", "D", "F", "L"]] = [] |
| 383 | self.imports: list[ImportBase] = [] |
| 384 | |
| 385 | self.options = options |
| 386 | self.is_stub = is_stub |
| 387 | self.errors = errors |
| 388 | self.strip_function_bodies = strip_function_bodies |
| 389 | self.path = path |
| 390 | |
| 391 | self.type_ignores: dict[int, list[str]] = {} |
| 392 | self.uses_template_strings = False |
| 393 | |
| 394 | # Cache of visit_X methods keyed by type of visited object |
| 395 | self.visitor_cache: dict[type, Callable[[AST | None], Any]] = {} |
| 396 | |
| 397 | def note(self, msg: str, line: int, column: int) -> None: |
| 398 | self.errors.report(line, column, msg, severity="note", code=codes.SYNTAX) |
| 399 | |
| 400 | def fail(self, msg: ErrorMessage, line: int, column: int, blocker: bool) -> None: |
| 401 | if blocker or not self.options.ignore_errors: |
| 402 | # Make sure self.errors reflects any type ignores that we have parsed |
| 403 | self.errors.set_file_ignored_lines( |
| 404 | self.path, self.type_ignores, self.options.ignore_errors |
| 405 | ) |
| 406 | self.errors.report(line, column, msg.value, blocker=blocker, code=msg.code) |
| 407 | |
| 408 | def fail_merge_overload(self, node: IfStmt) -> None: |
| 409 | self.fail( |
| 410 | message_registry.FAILED_TO_MERGE_OVERLOADS, |
| 411 | line=node.line, |
| 412 | column=node.column, |
| 413 | blocker=False, |
| 414 | ) |
| 415 | |
| 416 | def visit(self, node: AST | None) -> Any: |
| 417 | if node is None: |
| 418 | return None |
| 419 | typeobj = type(node) |
| 420 | visitor = self.visitor_cache.get(typeobj) |
| 421 | if visitor is None: |
| 422 | method = "visit_" + node.__class__.__name__ |
| 423 | visitor = getattr(self, method) |
| 424 | self.visitor_cache[typeobj] = visitor |
| 425 | |
| 426 | return visitor(node) |
| 427 | |
| 428 | def set_line(self, node: N, n: AstNode) -> N: |
no outgoing calls
no test coverage detected
searching dependent graphs…