|
59 | 59 | from mypy import errorcodes as codes, message_registry |
60 | 60 | from mypy.constant_fold import constant_fold_expr |
61 | 61 | from mypy.errorcodes import PROPERTY_DECORATOR, ErrorCode |
62 | | -from mypy.errors import Errors, report_internal_error |
| 62 | +from mypy.errors import ErrorInfo, Errors, report_internal_error |
63 | 63 | from mypy.exprtotype import TypeTranslationError, expr_to_unanalyzed_type |
64 | 64 | from mypy.message_registry import ErrorMessage |
65 | 65 | from mypy.messages import ( |
@@ -546,6 +546,8 @@ def __init__( |
546 | 546 | # import foo.bar |
547 | 547 | self.transitive_submodule_imports: dict[str, set[str]] = {} |
548 | 548 |
|
| 549 | + self.delayed_errors: dict[tuple[str, int, int], list[ErrorInfo]] = {} |
| 550 | + |
549 | 551 | # mypyc doesn't properly handle implementing an abstractproperty |
550 | 552 | # with a regular attribute so we make them properties |
551 | 553 | @property |
@@ -7093,6 +7095,7 @@ def _get_node_for_class_scoped_import( |
7093 | 7095 | ) -> SymbolNode | None: |
7094 | 7096 | if symbol_node is None: |
7095 | 7097 | return None |
| 7098 | + # TODO: remove supposedly unnecessary `f` |
7096 | 7099 | # I promise this type checks; I'm just making mypyc issues go away. |
7097 | 7100 | # mypyc is absolutely convinced that `symbol_node` narrows to a Var in the following, |
7098 | 7101 | # when it can also be a FuncBase. Once fixed, `f` in the following can be removed. |
@@ -7577,10 +7580,25 @@ def incomplete_feature_enabled(self, feature: str, ctx: Context) -> bool: |
7577 | 7580 | return True |
7578 | 7581 |
|
7579 | 7582 | def accept(self, node: Node) -> None: |
7580 | | - try: |
7581 | | - node.accept(self) |
7582 | | - except Exception as err: |
7583 | | - report_internal_error(err, self.errors.file, node.line, self.errors, self.options) |
| 7583 | + should_filter = isinstance(node, Statement) and not self.options.semantic_analysis_only |
| 7584 | + if should_filter: |
| 7585 | + filter_errors: bool | Callable[[str, ErrorInfo], bool] = lambda _, e: not e.blocker |
| 7586 | + else: |
| 7587 | + filter_errors = False |
| 7588 | + with self.msg.filter_errors(filter_errors=filter_errors, save_filtered_errors=True) as msg: |
| 7589 | + try: |
| 7590 | + node.accept(self) |
| 7591 | + except Exception as err: |
| 7592 | + report_internal_error(err, self.errors.file, node.line, self.errors, self.options) |
| 7593 | + |
| 7594 | + errors = msg.filtered_errors() |
| 7595 | + if errors: |
| 7596 | + # since nodes aren't hashable, carry things through values |
| 7597 | + assign_to = (self.cur_mod_id, node.line, node.column) |
| 7598 | + self.delayed_errors.setdefault(assign_to, []) |
| 7599 | + self.delayed_errors[assign_to].extend(errors) |
| 7600 | + |
| 7601 | + # print(node, [e.message for e in self.delayed_errors[node]]) |
7584 | 7602 |
|
7585 | 7603 | def expr_to_analyzed_type( |
7586 | 7604 | self, |
|
0 commit comments