Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a353ba9

Browse files
committed
Post process mypy notes
1. Omit `"x" defined here` as their position is not helpful. See python/mypy#10480 2. Combine errors with their notes if possible by merging their messages.
1 parent 7bd26a3 commit a353ba9

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

linter.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
import threading
2222
import getpass
2323

24-
from SublimeLinter.lint import PythonLinter
24+
from SublimeLinter.lint import LintMatch, PythonLinter
2525
from SublimeLinter.lint.linter import PermanentError
2626

2727

2828
MYPY = False
2929
if MYPY:
30-
from typing import Dict, DefaultDict, Optional, Protocol
30+
from typing import Dict, DefaultDict, Iterator, List, Optional, Protocol
3131

3232
class TemporaryDirectory(Protocol):
3333
name = None # type: str
@@ -121,6 +121,29 @@ def run(self, cmd, code):
121121
with locks[self.get_working_dir()]:
122122
return super().run(cmd, code)
123123

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+
124147

125148
class FakeTemporaryDirectory:
126149
def __init__(self, name):

0 commit comments

Comments
 (0)