Handle an error reported by a check. :param code: The error code found, e.g., E123. :param filename: The file in which the error was found. :param line_number: The line number (where counting starts at 1) at which the error occ
(
self,
code: str,
filename: str,
line_number: int,
column_number: int,
text: str,
physical_line: str | None = None,
)
| 373 | return self.decider.decision_for(code) |
| 374 | |
| 375 | def handle_error( |
| 376 | self, |
| 377 | code: str, |
| 378 | filename: str, |
| 379 | line_number: int, |
| 380 | column_number: int, |
| 381 | text: str, |
| 382 | physical_line: str | None = None, |
| 383 | ) -> int: |
| 384 | """Handle an error reported by a check. |
| 385 | |
| 386 | :param code: |
| 387 | The error code found, e.g., E123. |
| 388 | :param filename: |
| 389 | The file in which the error was found. |
| 390 | :param line_number: |
| 391 | The line number (where counting starts at 1) at which the error |
| 392 | occurs. |
| 393 | :param column_number: |
| 394 | The column number (where counting starts at 1) at which the error |
| 395 | occurs. |
| 396 | :param text: |
| 397 | The text of the error message. |
| 398 | :param physical_line: |
| 399 | The actual physical line causing the error. |
| 400 | :returns: |
| 401 | 1 if the error was reported. 0 if it was ignored. This is to allow |
| 402 | for counting of the number of errors found that were not ignored. |
| 403 | """ |
| 404 | disable_noqa = self.options.disable_noqa |
| 405 | # NOTE(sigmavirus24): Apparently we're provided with 0-indexed column |
| 406 | # numbers so we have to offset that here. |
| 407 | if not column_number: |
| 408 | column_number = 0 |
| 409 | error = Violation( |
| 410 | code, |
| 411 | filename, |
| 412 | line_number, |
| 413 | column_number + 1, |
| 414 | text, |
| 415 | physical_line, |
| 416 | ) |
| 417 | error_is_selected = ( |
| 418 | self.should_report_error(error.code) is Decision.Selected |
| 419 | ) |
| 420 | is_not_inline_ignored = error.is_inline_ignored(disable_noqa) is False |
| 421 | if error_is_selected and is_not_inline_ignored: |
| 422 | self.formatter.handle(error) |
| 423 | self.stats.record(error) |
| 424 | return 1 |
| 425 | return 0 |