Skip to content

Commit 89cff67

Browse files
Renée KöcherHealsrchl
authored
Catch mypy diagnostics which omit start column/end ranges (#72)
This commit adds a second line-regexp that catches mypy diagnostics which only include a starting line but have no column or end marker (i.e. --warn-unused-ignores). --------- Co-authored-by: Heals <[email protected]> Co-authored-by: Rafał Chłodnicki <[email protected]>
1 parent 2f569f6 commit 89cff67

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pylsp_mypy/plugin.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
)
3838
)
3939

40+
whole_line_pattern = re.compile( # certain mypy warnings do not report start-end ranges
41+
(
42+
r"^(?P<file>.+):(?P<start_line>\d+): "
43+
r"(?P<severity>\w+): (?P<message>.+?)(?: +\[(?P<code>.+)\])?$"
44+
)
45+
)
46+
4047
log = logging.getLogger(__name__)
4148

4249
# A mapping from workspace path to config file path
@@ -82,7 +89,8 @@ def parse_line(line: str, document: Optional[Document] = None) -> Optional[Dict[
8289
The dict with the lint data.
8390
8491
"""
85-
result = line_pattern.match(line)
92+
result = line_pattern.match(line) or whole_line_pattern.match(line)
93+
8694
if not result:
8795
return None
8896

@@ -95,9 +103,9 @@ def parse_line(line: str, document: Optional[Document] = None) -> Optional[Dict[
95103
return None
96104

97105
lineno = int(result["start_line"]) - 1 # 0-based line number
98-
offset = int(result["start_col"]) - 1 # 0-based offset
99-
end_lineno = int(result["end_line"]) - 1
100-
end_offset = int(result["end_col"]) # end is exclusive
106+
offset = int(result.groupdict().get("start_col", 1)) - 1 # 0-based offset
107+
end_lineno = int(result.groupdict().get("end_line", lineno + 1)) - 1
108+
end_offset = int(result.groupdict().get("end_col", 1)) # end is exclusive
101109

102110
severity = result["severity"]
103111
if severity not in ("error", "note"):

0 commit comments

Comments
 (0)