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

Skip to content

Commit db11a82

Browse files
committed
Support "--show-error-end" from newer mypy's
We can't enable this here for everyone because it has been just introduced in v0.981 (Sep 2022). But we can support its output format. Per spec, mypy might report `-1`s if it doesn't know a better value. We convert them to `None`s as that is what SL expects. Except for `line` which is mandatory in SL land and hereby reported on the first line of the buffer.
1 parent ad36dad commit db11a82

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

linter.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ class Mypy(PythonLinter):
5252
"""Provides an interface to mypy."""
5353

5454
regex = (
55-
r'^(?P<filename>.+?):(?P<line>\d+):((?P<col>\d+):)?\s*'
55+
r'^(?P<filename>.+?):'
56+
r'(?P<line>\d+|-1):((?P<col>\d+|-1):)?'
57+
r'((?P<end_line>\d+|-1):(?P<end_col>\d+|-1):)?\s*'
5658
r'(?P<error_type>[^:]+):\s(?P<message>.+?)(\s\s\[(?P<code>.+)\])?$'
5759
)
5860
line_col_base = (1, 1)
@@ -142,6 +144,14 @@ def find_errors(self, output):
142144
previous['message'] += '\n{}'.format(error.message)
143145
continue
144146

147+
# mypy might report `-1` for unknown values.
148+
# Only `line` is mandatory within SublimeLinter
149+
if error.match.group('line') == "-1": # type: ignore[attr-defined]
150+
error['line'] = 0
151+
for group in ('col', 'end_line', 'end_col'):
152+
if error.match.group(group) == "-1": # type: ignore[attr-defined]
153+
error[group] = None
154+
145155
errors.append(error)
146156
yield from errors
147157

tests/test_regex.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ def test_matches(self):
4141
'col': None,
4242
'message': '"dict" is not subscriptable, use "typing.Dict" instead'})
4343

44+
self.assertMatch(
45+
'codespell_lib\\tests\\test_basic.py:518:5:518:13: error: Module has no attribute "mkfifo" [attr-defined]', {
46+
'line': 517,
47+
'col': 4,
48+
'end_line': 517,
49+
'end_col': 12,
50+
})
51+
52+
self.assertMatch(
53+
'codespell_lib\\tests\\test_basic.py:-1:-1:-1:-1: error: Module has no attribute "mkfifo" [attr-defined]', {
54+
'line': 0,
55+
'col': None,
56+
'end_line': None,
57+
'end_col': None,
58+
})
59+
4460
def test_tmp_files_that_have_no_file_extension(self):
4561
self.assertMatch(
4662
'/tmp/yoeai32h2:6:1: error: Cannot find module named \'PackageName.lib\'', {

0 commit comments

Comments
 (0)