Skip to content
Merged
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
21 changes: 12 additions & 9 deletions pytest_mypy_plugins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,7 @@ def _add_aligned_message(word1: str, word2: str, error_message: str) -> str:
error_message += f" E: {word1[:_MAX_ALIGNMENT_WIDTH]}{extra}\n"
error_message += f" A: {word2[:_MAX_ALIGNMENT_WIDTH]}{extra}\n"
# Write an indicator character under the different columns.
error_message += " "
# sys.stderr.write(' ')
for pos in range(min(_MAX_ALIGNMENT_WIDTH, max_len)):
if word1[pos : pos + 1] != word2[pos : pos + 1]:
error_message += _ALIGNMENT_MARKER
break
else:
error_message += " "
error_message += "\n"
error_message += _build_first_difference_marker(word1, word2, max_len)
return error_message


Expand Down Expand Up @@ -403,3 +395,14 @@ def cd(path: str | Path) -> Iterator[None]:
yield
finally:
os.chdir(prev_cwd)


def _build_first_difference_marker(word1: str, word2: str, max_len: int) -> str:
marker_line: list[str] = [" "]
for pos in range(min(_MAX_ALIGNMENT_WIDTH, max_len)):
if word1[pos : pos + 1] != word2[pos : pos + 1]:
marker_line.append(_ALIGNMENT_MARKER)
break
marker_line.append(" ")
marker_line.append("\n")
return "".join(marker_line)
Loading