Error watcher that filters and separately collects `unreachable` errors, `redundant-expr` and `redundant-casts` errors, and revealed types and non-overlapping types when analysing code sections iteratively to help avoid making too-hasty reports.
| 389 | |
| 390 | |
| 391 | class IterationErrorWatcher(ErrorWatcher): |
| 392 | """Error watcher that filters and separately collects `unreachable` errors, |
| 393 | `redundant-expr` and `redundant-casts` errors, and revealed types and |
| 394 | non-overlapping types when analysing code sections iteratively to help avoid |
| 395 | making too-hasty reports.""" |
| 396 | |
| 397 | iteration_dependent_errors: IterationDependentErrors |
| 398 | |
| 399 | def __init__( |
| 400 | self, |
| 401 | errors: Errors, |
| 402 | iteration_dependent_errors: IterationDependentErrors, |
| 403 | *, |
| 404 | filter_errors: bool | Callable[[str, ErrorInfo], bool] = False, |
| 405 | save_filtered_errors: bool = False, |
| 406 | filter_deprecated: bool = False, |
| 407 | ) -> None: |
| 408 | super().__init__( |
| 409 | errors, |
| 410 | filter_errors=filter_errors, |
| 411 | save_filtered_errors=save_filtered_errors, |
| 412 | filter_deprecated=filter_deprecated, |
| 413 | ) |
| 414 | self.iteration_dependent_errors = iteration_dependent_errors |
| 415 | iteration_dependent_errors.uselessness_errors.append(set()) |
| 416 | iteration_dependent_errors.nonoverlapping_types.append({}) |
| 417 | iteration_dependent_errors.unreachable_lines.append(set()) |
| 418 | |
| 419 | def on_error(self, file: str, info: ErrorInfo) -> bool: |
| 420 | """Filter out the "iteration-dependent" errors and notes and store their |
| 421 | information to handle them after iteration is completed.""" |
| 422 | |
| 423 | iter_errors = self.iteration_dependent_errors |
| 424 | |
| 425 | if info.code in (codes.UNREACHABLE, codes.REDUNDANT_EXPR, codes.REDUNDANT_CAST): |
| 426 | iter_errors.uselessness_errors[-1].add( |
| 427 | (info.code, info.message, info.line, info.column, info.end_line, info.end_column) |
| 428 | ) |
| 429 | if info.code == codes.UNREACHABLE: |
| 430 | iter_errors.unreachable_lines[-1].update(range(info.line, info.end_line + 1)) |
| 431 | return True |
| 432 | |
| 433 | return super().on_error(file, info) |
| 434 | |
| 435 | |
| 436 | class Errors: |
no outgoing calls
no test coverage detected
searching dependent graphs…