MCPcopy
hub / github.com/psf/black / diff

Function diff

src/black/output.py:75–93  ·  view source on GitHub ↗

Return a unified diff string between strings `a` and `b`.

(a: str, b: str, a_name: str, b_name: str)

Source from the content-addressed store, hash-verified

73
74
75def diff(a: str, b: str, a_name: str, b_name: str) -> str:
76 """Return a unified diff string between strings `a` and `b`."""
77 import difflib
78
79 a_lines = _splitlines_no_ff(a)
80 b_lines = _splitlines_no_ff(b)
81 diff_lines = []
82 for line in difflib.unified_diff(
83 a_lines, b_lines, fromfile=a_name, tofile=b_name, n=5
84 ):
85 # Work around https://bugs.python.org/issue2142
86 # See:
87 # https://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html
88 if line[-1] == "\n":
89 diff_lines.append(line)
90 else:
91 diff_lines.append(line + "\n")
92 diff_lines.append("\\ No newline at end of file\n")
93 return "".join(diff_lines)
94
95
96def color_diff(contents: str) -> str:

Callers 8

format_file_in_placeFunction · 0.90
format_stdin_to_stdoutFunction · 0.90
assert_equivalentFunction · 0.90
assert_stableFunction · 0.90
test_code_option_diffMethod · 0.90
_assert_format_equalFunction · 0.90
ipynb_diffFunction · 0.85

Calls 2

_splitlines_no_ffFunction · 0.85
appendMethod · 0.45

Tested by 2

test_code_option_diffMethod · 0.72