|
21 | 21 | import threading |
22 | 22 | import getpass |
23 | 23 |
|
24 | | -from SublimeLinter.lint import PythonLinter |
| 24 | +from SublimeLinter.lint import LintMatch, PythonLinter |
25 | 25 | from SublimeLinter.lint.linter import PermanentError |
26 | 26 |
|
27 | 27 |
|
28 | 28 | MYPY = False |
29 | 29 | if MYPY: |
30 | | - from typing import Dict, DefaultDict, Optional, Protocol |
| 30 | + from typing import Dict, DefaultDict, Iterator, List, Optional, Protocol |
31 | 31 |
|
32 | 32 | class TemporaryDirectory(Protocol): |
33 | 33 | name = None # type: str |
@@ -121,6 +121,29 @@ def run(self, cmd, code): |
121 | 121 | with locks[self.get_working_dir()]: |
122 | 122 | return super().run(cmd, code) |
123 | 123 |
|
| 124 | + def find_errors(self, output): |
| 125 | + # type: (str) -> Iterator[LintMatch] |
| 126 | + errors = [] # type: List[LintMatch] |
| 127 | + for error in super().find_errors(output): |
| 128 | + # `"x" defined here` notes are unsorted and not helpful |
| 129 | + # See: https://github.com/python/mypy/issues/10480 |
| 130 | + # Introduced: https://github.com/python/mypy/pull/926 |
| 131 | + if error.message.endswith(' defined here'): |
| 132 | + continue |
| 133 | + |
| 134 | + if error.error_type == 'note': |
| 135 | + try: |
| 136 | + previous = errors[-1] |
| 137 | + except IndexError: |
| 138 | + pass |
| 139 | + else: |
| 140 | + if previous.line == error.line and previous.col == error.col: |
| 141 | + previous['message'] += '\n{}'.format(error.message) |
| 142 | + continue |
| 143 | + |
| 144 | + errors.append(error) |
| 145 | + yield from errors |
| 146 | + |
124 | 147 |
|
125 | 148 | class FakeTemporaryDirectory: |
126 | 149 | def __init__(self, name): |
|
0 commit comments