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
3 changes: 3 additions & 0 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,9 @@ def format_messages(
marker = "^"
if end_line == line and end_column > column:
marker = f'^{"~" * (end_column - column - 1)}'
elif end_line != line:
# just highlight the first line instead
marker = f'^{"~" * (len(source_line_expanded) - column - 1)}'
a.append(" " * (DEFAULT_SOURCE_OFFSET + column) + marker)
return a

Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/check-unreachable-code.test
Original file line number Diff line number Diff line change
Expand Up @@ -1619,3 +1619,14 @@ reveal_type(bar().attr) # N: Revealed type is "Never"
1 # not unreachable
reveal_type(foo().attr) # N: Revealed type is "Never"
1 # E: Statement is unreachable

[case testUnreachableStatementPrettyHighlighting]
# flags: --warn-unreachable --pretty
def x() -> None:
assert False
if 5:
pass
[out]
main:4: error: Statement is unreachable
if 5:
^~~~~
2 changes: 1 addition & 1 deletion test-data/unit/daemon.test
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Daemon stopped
Daemon started
foo.py:1: error: Function is missing a return type annotation
def f():
^
^~~~~~~~
foo.py:1: note: Use "-> None" if function does not return a value
Found 1 error in 1 file (checked 1 source file)
== Return code: 1
Expand Down