2121import threading
2222import getpass
2323
24- from SublimeLinter .lint import PythonLinter
24+ from SublimeLinter .lint import LintMatch , PythonLinter
2525from SublimeLinter .lint .linter import PermanentError
2626
2727
2828MYPY = False
2929if 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
@@ -53,7 +53,7 @@ class Mypy(PythonLinter):
5353
5454 regex = (
5555 r'^(?P<filename>.+?):(?P<line>\d+):((?P<col>\d+):)?\s*'
56- r'(?P<error_type>[^:]+):\s* (?P<message>.+?)(\s\s\[(?P<code>.+)\])?$'
56+ r'(?P<error_type>[^:]+):\s(?P<message>.+?)(\s\s\[(?P<code>.+)\])?$'
5757 )
5858 line_col_base = (1 , 1 )
5959 tempfile_suffix = 'py'
@@ -77,6 +77,7 @@ def cmd(self):
7777 '${args}' ,
7878 '--show-column-numbers' ,
7979 '--hide-error-context' ,
80+ '--no-error-summary' ,
8081 ]
8182 if self .filename :
8283 cmd .extend ([
@@ -120,6 +121,29 @@ def run(self, cmd, code):
120121 with locks [self .get_working_dir ()]:
121122 return super ().run (cmd , code )
122123
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+
123147
124148class FakeTemporaryDirectory :
125149 def __init__ (self , name ):
0 commit comments