Skip to content

Commit 7598bc0

Browse files
author
bscriver123 (aider)
committed
feat: Generate unified diff using difflib in code_diff function
1 parent 3d78ba9 commit 7598bc0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pytest_examples/lint.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations as _annotations
22

33
import re
4+
import difflib
45
from subprocess import PIPE, Popen
56
from textwrap import indent
67
from typing import TYPE_CHECKING
@@ -68,7 +69,9 @@ def replace_offset(m: re.Match):
6869

6970

7071
def code_diff(example: CodeExample, after: str, config: ExamplesConfig) -> str:
71-
def replace_at_line(match: re.Match) -> str:
72+
before_lines = sub_space(example.source, config).splitlines(keepends=True)
73+
after_lines = sub_space(after, config).splitlines(keepends=True)
74+
diff = ''.join(difflib.unified_diff(before_lines, after_lines, 'before', 'after'))
7275
offset = re.sub(r'\d+', lambda m: str(int(m.group(0)) + example.start_line), match.group(2))
7376
return f'{match.group(1)}{offset}{match.group(3)}'
7477

0 commit comments

Comments
 (0)