Skip to content

Commit 7c5e69b

Browse files
TH3CHARLiemsullivan
authored andcommitted
Fix incorrect error code indexing (#8248)
Fixes #8242
1 parent 300c846 commit 7c5e69b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

mypy/util.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,11 @@ def colorize(self, error: str) -> str:
607607
return (loc + self.style('error:', 'red', bold=True) +
608608
self.highlight_quote_groups(msg))
609609
codepos = msg.rfind('[')
610-
code = msg[codepos:]
611-
msg = msg[:codepos]
610+
if codepos != -1:
611+
code = msg[codepos:]
612+
msg = msg[:codepos]
613+
else:
614+
code = "" # no error code specified
612615
return (loc + self.style('error:', 'red', bold=True) +
613616
self.highlight_quote_groups(msg) + self.style(code, 'yellow'))
614617
elif ': note:' in error:

0 commit comments

Comments
 (0)