Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ def format_messages_default(
a.append(s)
if self.options.pretty:
# Add source code fragment and a location marker.
if severity == "error" and source_lines and line > 0:
if severity == "error" and source_lines and 0 < line <= len(source_lines):
source_line = source_lines[line - 1]
source_line_expanded = source_line.expandtabs()
min_column = len(source_line) - len(source_line.lstrip())
Expand Down
10 changes: 10 additions & 0 deletions mypy/test/testformatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

from unittest import TestCase, main

from mypy.errors import Errors
from mypy.options import Options
from mypy.util import split_words, trim_source_line


class FancyErrorFormattingTestCases(TestCase):
def test_pretty_error_past_end_of_file(self) -> None:
options = Options()
options.pretty = True
errors = Errors(options, read_source=lambda _: ["x = (1,"], hide_error_codes=True)
errors.set_file("main", None, options)
errors.report(2, 1, "Unexpected EOF while parsing")
assert errors.new_messages() == ["main:2: error: Unexpected EOF while parsing"]

def test_trim_source(self) -> None:
assert trim_source_line("0123456789abcdef", max_len=16, col=5, min_width=2) == (
"0123456789abcdef",
Expand Down
Loading