Skip to content

Commit ff6d7f4

Browse files
committed
Make --pretty work better on multi-line issues
We can just print the first line. Ideally, we would print the first line, last line, and explicitly elide the lines in between. That's for a future change!
1 parent 6aa44da commit ff6d7f4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

mypy/errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,9 @@ def format_messages(
10031003
marker = "^"
10041004
if end_line == line and end_column > column:
10051005
marker = f'^{"~" * (end_column - column - 1)}'
1006+
elif end_line != line:
1007+
# just highlight the first line instead
1008+
marker = f'^{"~" * (len(source_line_expanded) - column - 1)}'
10061009
a.append(" " * (DEFAULT_SOURCE_OFFSET + column) + marker)
10071010
return a
10081011

test-data/unit/check-unreachable-code.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,3 +1619,14 @@ reveal_type(bar().attr) # N: Revealed type is "Never"
16191619
1 # not unreachable
16201620
reveal_type(foo().attr) # N: Revealed type is "Never"
16211621
1 # E: Statement is unreachable
1622+
1623+
[case testUnreachableStatementPrettyHighlighting]
1624+
# flags: --warn-unreachable --pretty
1625+
def x() -> None:
1626+
assert False
1627+
if 5:
1628+
pass
1629+
[out]
1630+
main:4: error: Statement is unreachable
1631+
if 5:
1632+
^~~~~

0 commit comments

Comments
 (0)