Skip to content

Commit 8a10e40

Browse files
committed
Code review: docs, whatsnew, f-strings, news
1 parent 734b0bc commit 8a10e40

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ Summary --- release highlights
6565
6666
.. PEP-sized items next.
6767
68-
* :ref:`argparse <whatsnew315-color-difflib>`,
6968
7069
7170
New features
@@ -96,7 +95,7 @@ difflib
9695
.. _whatsnew315-color-difflib:
9796

9897
* Introduced the optional *color* parameter to :func:`difflib.unified_diff`,
99-
enabling colored output similar to what ``git diff`` displays.
98+
enabling color output similar to :program:`git diff`.
10099
This can be controlled by :ref:`environment variables
101100
<using-on-controlling-color>`.
102101
(Contributed by Douglas Thor in :gh:`133725`.)

Lib/difflib.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,9 @@ def unified_diff(a, b, fromfile='', tofile='', fromfiledate='',
11121112
For inputs that do not have trailing newlines, set the lineterm
11131113
argument to "" so that the output will be uniformly newline free.
11141114
1115-
Set *color* to ``True`` to inject ANSI color codes and make the output
1116-
look like what ``git diff --color`` shows.
1115+
Set *color* to ``True`` to enable output in color, similar to
1116+
:program:`git diff --color`. Even if enabled, it can be
1117+
:ref:`controlled using environment variables <using-on-controlling-color>`.
11171118
11181119
The unidiff format normally has a header for filenames and modification
11191120
times. Any or all of these may be specified using strings for
@@ -1150,13 +1151,13 @@ def unified_diff(a, b, fromfile='', tofile='', fromfiledate='',
11501151
started = True
11511152
fromdate = '\t{}'.format(fromfiledate) if fromfiledate else ''
11521153
todate = '\t{}'.format(tofiledate) if tofiledate else ''
1153-
yield '{}--- {}{}{}{}'.format(t.header, fromfile, fromdate, lineterm, t.reset)
1154-
yield '{}+++ {}{}{}{}'.format(t.header, tofile, todate, lineterm, t.reset)
1154+
yield f'{t.header}--- {fromfile}{fromdate}{lineterm}{t.reset}'
1155+
yield f'{t.header}+++ {tofile}{todate}{lineterm}{t.reset}'
11551156

11561157
first, last = group[0], group[-1]
11571158
file1_range = _format_range_unified(first[1], last[2])
11581159
file2_range = _format_range_unified(first[3], last[4])
1159-
yield '{}@@ -{} +{} @@{}{}'.format(t.hunk, file1_range, file2_range, lineterm, t.reset)
1160+
yield f'{t.hunk}@@ -{file1_range} +{file2_range} @@{lineterm}{t.reset}'
11601161

11611162
for tag, i1, i2, j1, j2 in group:
11621163
if tag == 'equal':
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Added a ``color`` option to :func:`difflib.unified_diff` that injects ANSI color
2-
codes to mimic ``git diff`` colors.
1+
Added a *color* option to :func:`difflib.unified_diff` that colors output
2+
similar to :program:`git diff`.

0 commit comments

Comments
 (0)