MCPcopy Index your code
hub / github.com/python/mypy / render_diff_range

Function render_diff_range

mypy/test/helpers.py:75–107  ·  view source on GitHub ↗
(
    ranges: list[tuple[int, int]],
    content: list[str],
    *,
    colour: str | None = None,
    output: IO[str] = sys.stderr,
    indent: int = 2,
)

Source from the content-addressed store, hash-verified

73
74
75def render_diff_range(
76 ranges: list[tuple[int, int]],
77 content: list[str],
78 *,
79 colour: str | None = None,
80 output: IO[str] = sys.stderr,
81 indent: int = 2,
82) -> None:
83 for i, line_range in enumerate(ranges):
84 is_matching = i % 2 == 1
85 lines = content[line_range[0] : line_range[1]]
86 for j, line in enumerate(lines):
87 if (
88 is_matching
89 # elide the middle of matching blocks
90 and j >= 3
91 and j < len(lines) - 3
92 ):
93 if j == 3:
94 output.write(" " * indent + "...\n")
95 continue
96
97 if not is_matching and colour:
98 output.write(colour)
99
100 output.write(" " * indent + line)
101
102 if not is_matching:
103 if colour:
104 output.write("\033[0m")
105 output.write(" (diff)")
106
107 output.write("\n")
108
109
110def dump_original_errors(errors: list[str]) -> None:

Callers 2

Calls 3

enumerateFunction · 0.85
lenFunction · 0.85
writeMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…