From 367dc5588c683a862adb190b02718e531b0e155d Mon Sep 17 00:00:00 2001 From: Tomasz Date: Sat, 18 Jul 2026 14:45:41 +0200 Subject: [PATCH 01/18] difflib: expose autojunk flag from SequenceMatcher to public methods/functions --- Lib/difflib.py | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/Lib/difflib.py b/Lib/difflib.py index ae8b284b4d3647..a95242274d2cfb 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -664,7 +664,7 @@ def real_quick_ratio(self): __class_getitem__ = classmethod(GenericAlias) -def get_close_matches(word, possibilities, n=3, cutoff=0.6): +def get_close_matches(word, possibilities, n=3, cutoff=0.6, autojunk=True): """Use SequenceMatcher to return list of the best "good enough" matches. word is a sequence for which close matches are desired (typically a @@ -698,7 +698,7 @@ def get_close_matches(word, possibilities, n=3, cutoff=0.6): if not 0.0 <= cutoff <= 1.0: raise ValueError("cutoff must be in [0.0, 1.0]: %r" % (cutoff,)) result = [] - s = SequenceMatcher() + s = SequenceMatcher(autojunk=autojunk) s.set_seq2(word) for x in possibilities: s.set_seq1(x) @@ -810,7 +810,7 @@ class Differ: + 5. Flat is better than nested. """ - def __init__(self, linejunk=None, charjunk=None): + def __init__(self, linejunk=None, charjunk=None, autojunk=True): """ Construct a text differencer, with optional filters. @@ -828,10 +828,13 @@ def __init__(self, linejunk=None, charjunk=None): module-level function `IS_CHARACTER_JUNK` may be used to filter out whitespace characters (a blank or tab; **note**: bad idea to include newline in this!). Use of IS_CHARACTER_JUNK is recommended. + - `autojunk`: automatic junk diff heruistic + (refer to :class:`SequenceMatcher` for specifics). """ self.linejunk = linejunk self.charjunk = charjunk + self.autojunk = autojunk def compare(self, a, b): r""" @@ -859,7 +862,7 @@ def compare(self, a, b): + emu """ - cruncher = SequenceMatcher(self.linejunk, a, b) + cruncher = SequenceMatcher(self.linejunk, a, b, autojunk=self.autojunk) for tag, alo, ahi, blo, bhi in cruncher.get_opcodes(): if tag == 'replace': g = self._fancy_replace(a, alo, ahi, b, blo, bhi) @@ -920,7 +923,7 @@ def _fancy_replace(self, a, alo, ahi, b, blo, bhi): # Later, more pathological cases prompted removing recursion # entirely. cutoff = 0.74999 - cruncher = SequenceMatcher(self.charjunk) + cruncher = SequenceMatcher(self.charjunk, autojunk=self.autojunk) crqr = cruncher.real_quick_ratio cqr = cruncher.quick_ratio cr = cruncher.ratio @@ -1099,7 +1102,7 @@ def _format_range_unified(start, stop): return '{},{}'.format(beginning, length) def unified_diff(a, b, fromfile='', tofile='', fromfiledate='', - tofiledate='', n=3, lineterm='\n', *, color=False): + tofiledate='', n=3, lineterm='\n', *, color=False, autojunk=True): r""" Compare two sequences of lines; generate the delta as a unified diff. @@ -1120,6 +1123,9 @@ def unified_diff(a, b, fromfile='', tofile='', fromfiledate='', 'git diff --color'. Even if enabled, it can be controlled using environment variables such as 'NO_COLOR'. + Set `autojunk` to False if you don't want automated junk heruistic. + See details in :class:`SequenceMatcher. + The unidiff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. @@ -1150,7 +1156,7 @@ def unified_diff(a, b, fromfile='', tofile='', fromfiledate='', _check_types(a, b, fromfile, tofile, fromfiledate, tofiledate, lineterm) started = False - for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n): + for group in SequenceMatcher(None,a,b,autojunk=autojunk).get_grouped_opcodes(n): if not started: started = True fromdate = '\t{}'.format(fromfiledate) if fromfiledate else '' @@ -1193,7 +1199,7 @@ def _format_range_context(start, stop): # See http://www.unix.org/single_unix_specification/ def context_diff(a, b, fromfile='', tofile='', - fromfiledate='', tofiledate='', n=3, lineterm='\n'): + fromfiledate='', tofiledate='', n=3, lineterm='\n', autojunk=True): r""" Compare two sequences of lines; generate the delta as a context diff. @@ -1216,6 +1222,10 @@ def context_diff(a, b, fromfile='', tofile='', The modification times are normally expressed in the ISO 8601 format. If not specified, the strings default to blanks. + The kwarg `autojunk` sets up automated junk hereuistic with + :class:`SequenceMatcher`, which is used under the hood in this function. + See documentation of :class:`SequenceMatcher` for details. + Example: >>> print(''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(True), @@ -1239,7 +1249,7 @@ def context_diff(a, b, fromfile='', tofile='', _check_types(a, b, fromfile, tofile, fromfiledate, tofiledate, lineterm) prefix = dict(insert='+ ', delete='- ', replace='! ', equal=' ') started = False - for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n): + for group in SequenceMatcher(None,a,b, autojunk=autojunk).get_grouped_opcodes(n): if not started: started = True fromdate = '\t{}'.format(fromfiledate) if fromfiledate else '' @@ -1321,7 +1331,7 @@ def decode(s): for line in lines: yield line.encode('ascii', 'surrogateescape') -def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK): +def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK, autojunk=True): r""" Compare `a` and `b` (lists of strings); return a `Differ`-style delta. @@ -1339,6 +1349,8 @@ def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK): whitespace characters (a blank or tab; note: it's a bad idea to include newline in this!). + - autojunk: automatic junk heuristic - refer to :class:`SequenceMatcher` for details + Tools/scripts/ndiff.py is a command-line front-end to this function. Example: @@ -1356,10 +1368,10 @@ def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK): + tree + emu """ - return Differ(linejunk, charjunk).compare(a, b) + return Differ(linejunk, charjunk, autojunk).compare(a, b) def _mdiff(fromlines, tolines, context=None, linejunk=None, - charjunk=IS_CHARACTER_JUNK): + charjunk=IS_CHARACTER_JUNK, autojunk=True): r"""Returns generator yielding marked up from/to side by side differences. Arguments: @@ -1369,6 +1381,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None, if None, all from/to text lines will be generated. linejunk -- passed on to ndiff (see ndiff documentation) charjunk -- passed on to ndiff (see ndiff documentation) + autojunk -- passed on to ndiff (see ndiff documentation) This function returns an iterator which returns a tuple: (from line tuple, to line tuple, boolean flag) @@ -1398,7 +1411,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None, change_re = re.compile(r'(\++|\-+|\^+)') # create the difference iterator to generate the differences - diff_lines_iterator = ndiff(fromlines,tolines,linejunk,charjunk) + diff_lines_iterator = ndiff(fromlines, tolines, linejunk, charjunk, autojunk) def _make_line(lines, format_key, side, num_lines=[0,0]): """Returns line of text with user's change markup and line formatting. @@ -1738,14 +1751,14 @@ class HtmlDiff(object): _default_prefix = 0 def __init__(self,tabsize=8,wrapcolumn=None,linejunk=None, - charjunk=IS_CHARACTER_JUNK): + charjunk=IS_CHARACTER_JUNK, autojunk=True): """HtmlDiff instance initializer Arguments: tabsize -- tab stop spacing, defaults to 8. wrapcolumn -- column number where lines are broken and wrapped, defaults to None where lines are not wrapped. - linejunk,charjunk -- keyword arguments passed into ndiff() (used by + linejunk, charjunk, autojunk -- keyword arguments passed into ndiff() (used by HtmlDiff() to generate the side by side HTML differences). See ndiff() documentation for argument default values and descriptions. """ @@ -1753,6 +1766,7 @@ def __init__(self,tabsize=8,wrapcolumn=None,linejunk=None, self._wrapcolumn = wrapcolumn self._linejunk = linejunk self._charjunk = charjunk + self._autojunk = autojunk def make_file(self, fromlines, tolines, fromdesc='', todesc='', context=False, numlines=5, *, charset='utf-8'): @@ -2024,7 +2038,7 @@ def make_table(self,fromlines,tolines,fromdesc='',todesc='',context=False, else: context_lines = None diffs = _mdiff(fromlines,tolines,context_lines,linejunk=self._linejunk, - charjunk=self._charjunk) + charjunk=self._charjunk, autojunk=self._autojunk) # set up iterator to wrap lines that exceed desired width if self._wrapcolumn: From 9a822c430a6565b9380b25fc9d0f1616a1af8df1 Mon Sep 17 00:00:00 2001 From: Tomasz Date: Sat, 18 Jul 2026 16:44:58 +0200 Subject: [PATCH 02/18] difflib: update news for gh118150 --- ...26-07-18-16-43-02.gh-issue-118150.x0mV8P.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst diff --git a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst new file mode 100644 index 00000000000000..9dd7791430d234 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst @@ -0,0 +1,17 @@ +Expose automated junk heruistic flag to the public in difflib. + +This changes aims to expose autojunk flag (automated junk heuristic) of +:class:`SequenceMatcher` (which by default is set up to be True) for the +public methods and functions of the difflib module in order that the user +can choose behavior of this option. + +# # Uncomment one of these "section:" lines to specify which section # this +entry should go in in Misc/NEWS.d. # #.. section: Security #.. section: Core +and Builtins #.. section: Library #.. section: Documentation #.. section: +Tests #.. section: Build #.. section: Windows #.. section: macOS #.. +section: IDLE #.. section: Tools/Demos #.. section: C API + +# Write your Misc/NEWS.d entry below. It should be a simple ReST paragraph. +# Don't start with "- Issue #: " or "- gh-issue-: " or that sort of +stuff. +########################################################################### From 5e2f622820269bb4846113b734a7fb3753d6ceb6 Mon Sep 17 00:00:00 2001 From: Tomasz Date: Sat, 18 Jul 2026 16:49:57 +0200 Subject: [PATCH 03/18] difflib: fix typyos in docstrings --- Lib/difflib.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/difflib.py b/Lib/difflib.py index a95242274d2cfb..65acc9140bd519 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -828,7 +828,7 @@ def __init__(self, linejunk=None, charjunk=None, autojunk=True): module-level function `IS_CHARACTER_JUNK` may be used to filter out whitespace characters (a blank or tab; **note**: bad idea to include newline in this!). Use of IS_CHARACTER_JUNK is recommended. - - `autojunk`: automatic junk diff heruistic + - `autojunk`: automatic junk diff heuristic (refer to :class:`SequenceMatcher` for specifics). """ @@ -1123,7 +1123,7 @@ def unified_diff(a, b, fromfile='', tofile='', fromfiledate='', 'git diff --color'. Even if enabled, it can be controlled using environment variables such as 'NO_COLOR'. - Set `autojunk` to False if you don't want automated junk heruistic. + Set `autojunk` to False if you don't want automated junk heuristic. See details in :class:`SequenceMatcher. The unidiff format normally has a header for filenames and modification @@ -1222,7 +1222,7 @@ def context_diff(a, b, fromfile='', tofile='', The modification times are normally expressed in the ISO 8601 format. If not specified, the strings default to blanks. - The kwarg `autojunk` sets up automated junk hereuistic with + The kwarg `autojunk` sets up automated junk heuristic with :class:`SequenceMatcher`, which is used under the hood in this function. See documentation of :class:`SequenceMatcher` for details. From 7d864736382ed5c3e6509e152ab734eb38e5c72a Mon Sep 17 00:00:00 2001 From: Tomasz Date: Sat, 18 Jul 2026 17:08:17 +0200 Subject: [PATCH 04/18] gh-118150: difflib - fix NEWS issue with ref. not found --- .../Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst index 9dd7791430d234..71a2738edf76c1 100644 --- a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst +++ b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst @@ -1,8 +1,8 @@ Expose automated junk heruistic flag to the public in difflib. This changes aims to expose autojunk flag (automated junk heuristic) of -:class:`SequenceMatcher` (which by default is set up to be True) for the -public methods and functions of the difflib module in order that the user +SequenceMatcher class (which by default is set up to be True) for the +public methods and functions of the difflib module in order that the user can choose behavior of this option. # # Uncomment one of these "section:" lines to specify which section # this From b5213c98ed265398e806e3686445113bf57d36f5 Mon Sep 17 00:00:00 2001 From: Tomasz Date: Sun, 19 Jul 2026 11:31:40 +0200 Subject: [PATCH 05/18] gh-118150: difflib - fix NEWS doc for ReST --- .../2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst index 71a2738edf76c1..e2115b63deed40 100644 --- a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst +++ b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst @@ -1,9 +1,13 @@ Expose automated junk heruistic flag to the public in difflib. -This changes aims to expose autojunk flag (automated junk heuristic) of -SequenceMatcher class (which by default is set up to be True) for the -public methods and functions of the difflib module in order that the user -can choose behavior of this option. +.. section: Library + + This change exposes the *autojunk* kwarg — used for turning on/off + the automated junk heuristic in the :class:`SequenceMatcher` (which + defaults to ``True``, meaning this heuristic was always performed + in :mod:`difflib`) — to the public methods and functions of + the :mod:`difflib`, so that users can change the behavior of this option. + See the :class:`SequenceMatcher` documentation for details. # # Uncomment one of these "section:" lines to specify which section # this entry should go in in Misc/NEWS.d. # #.. section: Security #.. section: Core From 7d7a35b250eb93d00397866e06ddf85b63fcee77 Mon Sep 17 00:00:00 2001 From: Tomasz Date: Mon, 20 Jul 2026 13:45:00 +0200 Subject: [PATCH 06/18] gh-118150: difflib - remove template notes from NEWS --- .../2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst index e2115b63deed40..ecd250e7b5260d 100644 --- a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst +++ b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst @@ -8,14 +8,3 @@ Expose automated junk heruistic flag to the public in difflib. in :mod:`difflib`) — to the public methods and functions of the :mod:`difflib`, so that users can change the behavior of this option. See the :class:`SequenceMatcher` documentation for details. - -# # Uncomment one of these "section:" lines to specify which section # this -entry should go in in Misc/NEWS.d. # #.. section: Security #.. section: Core -and Builtins #.. section: Library #.. section: Documentation #.. section: -Tests #.. section: Build #.. section: Windows #.. section: macOS #.. -section: IDLE #.. section: Tools/Demos #.. section: C API - -# Write your Misc/NEWS.d entry below. It should be a simple ReST paragraph. -# Don't start with "- Issue #: " or "- gh-issue-: " or that sort of -stuff. -########################################################################### From bd982988c49f912d697c10f8c27f1dfed047e63e Mon Sep 17 00:00:00 2001 From: Tomasz Date: Wed, 22 Jul 2026 13:44:33 +0200 Subject: [PATCH 07/18] gh-118150: CI fix for check-docs --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d247f99aefe174..b7af4a1598ba20 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -674,7 +674,7 @@ jobs: build-windows-msi, build-ubuntu-ssltests, test-hypothesis, - cifuzz, + cifuzz allowed-skips: >- ${{ !fromJSON(needs.build-context.outputs.run-docs) && 'check-docs,' || '' }} ${{ From af14a4f5435b8f234d8a1718e0f25ecb8ea82a58 Mon Sep 17 00:00:00 2001 From: Tomasz Date: Wed, 22 Jul 2026 13:56:26 +0200 Subject: [PATCH 08/18] gh-118150: how to reference a class in NEWS file? --- .../Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst index ecd250e7b5260d..417cebcb9da45d 100644 --- a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst +++ b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst @@ -3,8 +3,8 @@ Expose automated junk heruistic flag to the public in difflib. .. section: Library This change exposes the *autojunk* kwarg — used for turning on/off - the automated junk heuristic in the :class:`SequenceMatcher` (which - defaults to ``True``, meaning this heuristic was always performed + the automated junk heuristic in the :class:`difflib.SequenceMatcher` + (which defaults to ``True``, meaning this heuristic was always performed in :mod:`difflib`) — to the public methods and functions of the :mod:`difflib`, so that users can change the behavior of this option. - See the :class:`SequenceMatcher` documentation for details. + See the :class:`difflib.SequenceMatcher` documentation for details. From 9dc95bd302bfbb941f93c94a3d542b0be55d9cf9 Mon Sep 17 00:00:00 2001 From: Tomasz Kazimierczak Date: Mon, 3 Aug 2026 07:59:39 +0200 Subject: [PATCH 09/18] gh-118150: apply suggestions from code review Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Lib/difflib.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Lib/difflib.py b/Lib/difflib.py index 1666e8072fe909..d9d970f2b2d2da 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -664,7 +664,7 @@ def real_quick_ratio(self): __class_getitem__ = classmethod(GenericAlias) -def get_close_matches(word, possibilities, n=3, cutoff=0.6, autojunk=True): +def get_close_matches(word, possibilities, n=3, cutoff=0.6, *, autojunk=True): """Use SequenceMatcher to return list of the best "good enough" matches. word is a sequence for which close matches are desired (typically a @@ -810,7 +810,7 @@ class Differ: + 5. Flat is better than nested. """ - def __init__(self, linejunk=None, charjunk=None, autojunk=True): + def __init__(self, linejunk=None, charjunk=None, *, autojunk=True): """ Construct a text differencer, with optional filters. @@ -1102,7 +1102,7 @@ def _format_range_unified(start, stop): return '{},{}'.format(beginning, length) def unified_diff(a, b, fromfile='', tofile='', fromfiledate='', - tofiledate='', n=3, lineterm='\n', *, color=False, autojunk=True): + tofiledate='', n=3, lineterm='\n', *, autojunk=True, color=False): r""" Compare two sequences of lines; generate the delta as a unified diff. @@ -1156,7 +1156,7 @@ def unified_diff(a, b, fromfile='', tofile='', fromfiledate='', _check_types(a, b, fromfile, tofile, fromfiledate, tofiledate, lineterm) started = False - for group in SequenceMatcher(None,a,b,autojunk=autojunk).get_grouped_opcodes(n): + for group in SequenceMatcher(None, a, b, autojunk=autojunk).get_grouped_opcodes(n): if not started: started = True fromdate = '\t{}'.format(fromfiledate) if fromfiledate else '' @@ -1199,7 +1199,7 @@ def _format_range_context(start, stop): # See http://www.unix.org/single_unix_specification/ def context_diff(a, b, fromfile='', tofile='', - fromfiledate='', tofiledate='', n=3, lineterm='\n', autojunk=True): + fromfiledate='', tofiledate='', n=3, lineterm='\n', *, autojunk=True): r""" Compare two sequences of lines; generate the delta as a context diff. @@ -1249,7 +1249,7 @@ def context_diff(a, b, fromfile='', tofile='', _check_types(a, b, fromfile, tofile, fromfiledate, tofiledate, lineterm) prefix = dict(insert='+ ', delete='- ', replace='! ', equal=' ') started = False - for group in SequenceMatcher(None,a,b, autojunk=autojunk).get_grouped_opcodes(n): + for group in SequenceMatcher(None, a, b, autojunk=autojunk).get_grouped_opcodes(n): if not started: started = True fromdate = '\t{}'.format(fromfiledate) if fromfiledate else '' @@ -1331,7 +1331,7 @@ def decode(s): for line in lines: yield line.encode('ascii', 'surrogateescape') -def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK, autojunk=True): +def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK, *, autojunk=True): r""" Compare `a` and `b` (lists of strings); return a `Differ`-style delta. From e4cd72a75ed034a7ec3bfedd810a2395784aaab3 Mon Sep 17 00:00:00 2001 From: Tomasz Kazimierczak Date: Wed, 5 Aug 2026 01:02:15 +0200 Subject: [PATCH 10/18] gh-118150: revert CI change (form bd98298) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 80dee4af2b26f9..8d4bd4a346f2e6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -656,7 +656,7 @@ jobs: build-emscripten, build-ubuntu-ssltests, test-hypothesis, - cifuzz + cifuzz, allowed-skips: >- ${{ !fromJSON(needs.build-context.outputs.run-docs) && 'check-docs,' || '' }} ${{ From 35866162f83df5a51e21eecd1d58b5eb9dd57111 Mon Sep 17 00:00:00 2001 From: Tomasz Kazimierczak Date: Wed, 5 Aug 2026 01:04:35 +0200 Subject: [PATCH 11/18] gh-118150: Update difflib Differ for keyword-only argument Co-authored-by: Petr Viktorin --- Lib/difflib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/difflib.py b/Lib/difflib.py index d9d970f2b2d2da..6af1eb5091c3c1 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -1368,7 +1368,7 @@ def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK, *, autojunk=True): + tree + emu """ - return Differ(linejunk, charjunk, autojunk).compare(a, b) + return Differ(linejunk, charjunk, autojunk=autojunk).compare(a, b) def _mdiff(fromlines, tolines, context=None, linejunk=None, charjunk=IS_CHARACTER_JUNK, autojunk=True): From 1197f62675c7b5bed208c0805b8192c800bf41e4 Mon Sep 17 00:00:00 2001 From: Tomasz Date: Wed, 5 Aug 2026 12:44:53 +0200 Subject: [PATCH 12/18] gh-118150: update doc and fix NEWS; set keyword-only --- Doc/library/difflib.rst | 63 ++++++++++++++++--- Lib/difflib.py | 4 +- ...-07-18-16-43-02.gh-issue-118150.x0mV8P.rst | 17 +++-- 3 files changed, 64 insertions(+), 20 deletions(-) diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst index 3ed4768b6a1413..9c657e9825bee2 100644 --- a/Doc/library/difflib.rst +++ b/Doc/library/difflib.rst @@ -19,6 +19,15 @@ about file differences in various formats, including HTML and context and unifie diffs. For comparing directories and files, see also, the :mod:`filecmp` module. +.. versionchanged:: 3.16 + Exposed *autojunk* parameter of :class:`SequenceMatcher` in public functions + and classes of this module (:class:`Differ`, :class:`HtmlDiff`, :func:`ndiff`, + :func:`unified_diff`, :func:`context_diff`). For backward compatibility + this parameter is set everywhere to be `True` by default. + + See :gh:`118150` for motivation and reasons. + + .. class:: SequenceMatcher :noindex: @@ -78,6 +87,8 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. the sequences contain whitespace characters, such as spaces, tabs or line breaks. + + .. class:: HtmlDiff This class can be used to create an HTML table (or a complete HTML file @@ -93,7 +104,7 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. The constructor for this class is: - .. method:: __init__(tabsize=8, wrapcolumn=None, linejunk=None, charjunk=IS_CHARACTER_JUNK) + .. method:: __init__(tabsize=8, wrapcolumn=None, linejunk=None, charjunk=IS_CHARACTER_JUNK, *, autojunk=True): Initializes instance of :class:`HtmlDiff`. @@ -104,8 +115,14 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. broken and wrapped, defaults to ``None`` where lines are not wrapped. *linejunk* and *charjunk* are optional keyword arguments passed into :func:`ndiff` - (used by :class:`HtmlDiff` to generate the side by side HTML differences). See - :func:`ndiff` documentation for argument default values and descriptions. + (used by :class:`HtmlDiff` to generate the side by side HTML differences). + See :func:`ndiff` documentation for argument default values and descriptions. + + .. versionadded:: 3.16 + *autojunk* parameter + + Keyword-only *autojunk* flag is for setting on/off automatic junk heuristic + of :class:`SequenceMatcher`. The following methods are public: @@ -148,7 +165,7 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. -.. function:: context_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n') +.. function:: context_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n', *, autojunk=True) Compare *a* and *b* (lists of strings); return a delta (a :term:`generator` generating the delta lines) in context diff format. @@ -166,6 +183,12 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. For inputs that do not have trailing newlines, set the *lineterm* argument to ``""`` so that the output will be uniformly newline free. + .. versionadded:: 3.16 + *autojunk* kwarg + + The kwarg-only parameter *autojunk* sets up automatic junk heuristic of + :class:`SequenceMatcher`. + The context diff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for *fromfile*, *tofile*, *fromfiledate*, and *tofiledate*. The modification times are normally @@ -195,7 +218,7 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. See :ref:`difflib-interface` for a more detailed example. -.. function:: get_close_matches(word, possibilities, n=3, cutoff=0.6) +.. function:: get_close_matches(word, possibilities, n=3, cutoff=0.6, *, autojunk=True) Return a list of the best "good enough" matches. *word* is a sequence for which close matches are desired (typically a string), and *possibilities* is a list of @@ -207,6 +230,12 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. Optional argument *cutoff* (default ``0.6``) is a float in the range [0, 1]. Possibilities that don't score at least that similar to *word* are ignored. + .. versionadded:: 3.16 + *autojunk* parameter + + Keyword-only optional *autojunk* param is a flag for turning on/off + an automatic junk heuristic of :class:`SequenceMatcher`. + The best (no more than *n*) matches among the possibilities are returned in a list, sorted by similarity score, most similar first. @@ -221,7 +250,7 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. ['except'] -.. function:: ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK) +.. function:: ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK, *, autojunk=True) Compare *a* and *b* (lists of strings); return a :class:`Differ`\ -style delta (a :term:`generator` generating the delta lines). @@ -242,6 +271,13 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. function :func:`IS_CHARACTER_JUNK`, which filters out whitespace characters (a blank or tab; it's a bad idea to include newline in this!). + .. versionadded:: 3.16 + + *autojunk*: keyword-only parameter for setting on/off automatic junk heuristic + of :class:`SequenceMatcher`. + + Example: + >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True), ... 'ore\ntree\nemu\n'.splitlines(keepends=True)) >>> print(''.join(diff), end="") @@ -279,7 +315,7 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. emu -.. function:: unified_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n', *, color=False) +.. function:: unified_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n', *, autojunk=True, color=False) Compare *a* and *b* (lists of strings); return a delta (a :term:`generator` generating the delta lines) in unified diff format. @@ -302,6 +338,13 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. :program:`git diff --color`. Even if enabled, it can be :ref:`controlled using environment variables `. + .. versionadded:: 3.16 + + keyword-only *autojunk* parameter. + + Set *autojunk* to ``False`` to disable automatic junk heuristic + of underlying :class:`SequenceMatcher`. + The unified diff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for *fromfile*, *tofile*, *fromfiledate*, and *tofiledate*. The modification times are normally @@ -327,7 +370,6 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. .. versionchanged:: 3.15 Added the *color* parameter. - .. function:: diff_bytes(dfunc, a, b, fromfile=b'', tofile=b'', fromfiledate=b'', tofiledate=b'', n=3, lineterm=b'\n') Compare *a* and *b* (lists of bytes objects) using *dfunc*; yield a @@ -658,7 +700,7 @@ locality, at the occasional cost of producing a longer diff. The :class:`Differ` class has this constructor: -.. class:: Differ(linejunk=None, charjunk=None) +.. class:: Differ(linejunk=None, charjunk=None, *, autojunk=True) :noindex: Optional keyword parameters *linejunk* and *charjunk* are for filter functions @@ -672,6 +714,9 @@ The :class:`Differ` class has this constructor: length 1), and returns true if the character is junk. The default is ``None``, meaning that no character is considered junk. + *autojunk*: Flag for automatic junk heuristic (refer to :class:`SequenceMatcher` + for specifics). + These junk-filtering functions speed up matching to find differences and do not cause any differing lines or characters to be ignored. Read the description of the diff --git a/Lib/difflib.py b/Lib/difflib.py index 6af1eb5091c3c1..0e95d5e9624214 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -1371,7 +1371,7 @@ def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK, *, autojunk=True): return Differ(linejunk, charjunk, autojunk=autojunk).compare(a, b) def _mdiff(fromlines, tolines, context=None, linejunk=None, - charjunk=IS_CHARACTER_JUNK, autojunk=True): + charjunk=IS_CHARACTER_JUNK, *, autojunk=True): r"""Returns generator yielding marked up from/to side by side differences. Arguments: @@ -1751,7 +1751,7 @@ class HtmlDiff(object): _default_prefix = 0 def __init__(self,tabsize=8,wrapcolumn=None,linejunk=None, - charjunk=IS_CHARACTER_JUNK, autojunk=True): + charjunk=IS_CHARACTER_JUNK, *, autojunk=True): """HtmlDiff instance initializer Arguments: diff --git a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst index 417cebcb9da45d..169a3c6bb96267 100644 --- a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst +++ b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst @@ -1,10 +1,9 @@ -Expose automated junk heruistic flag to the public in difflib. +Expose automated junk heuristic kwarg-only flag `autojunk` from +:class:`difflib.SequenceMatcher` to the public functions +and class methods in the :mod:`difflib`. This option defaults +to ``True``, meaning that until now it was always implicitly "on" +in other methods and classes of :mod:`difflib` which are relying +on :class:`difflib.SequenceMatcher`. -.. section: Library - - This change exposes the *autojunk* kwarg — used for turning on/off - the automated junk heuristic in the :class:`difflib.SequenceMatcher` - (which defaults to ``True``, meaning this heuristic was always performed - in :mod:`difflib`) — to the public methods and functions of - the :mod:`difflib`, so that users can change the behavior of this option. - See the :class:`difflib.SequenceMatcher` documentation for details. +See the :class:`difflib.SequenceMatcher` documentation for details +of this flag purpose and issue :gh:`118150` for the motivation. From 1843999d1b91a757776e8e33c20b227d2f9b4979 Mon Sep 17 00:00:00 2001 From: Tomasz Date: Wed, 5 Aug 2026 13:06:54 +0200 Subject: [PATCH 13/18] add note to Doc/whatsnew/3.16 --- Doc/whatsnew/3.16.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index 662defa709a246..4b5201db2e9e2e 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -257,6 +257,15 @@ ctypes (Contributed by Peter Bierma in :gh:`153903`.) +difflib +------- + +* Expose *autojunk* parameter from :class:`difflib.SequenceMatcher` in public + functions and class methods which allows to modifty behavior of automatic + junk heuristic in :mod:`difflib`. + (Contributed by Tomasz Kazimierczak in :gh:`118150`) + + encodings --------- From 3da543a1a4c318e64c55aca84e44c4ba674dd0ef Mon Sep 17 00:00:00 2001 From: Tomasz Date: Wed, 5 Aug 2026 14:11:57 +0200 Subject: [PATCH 14/18] gh-118150: Add unit tests for `autojunk` parameter in `difflib` (#153959) * Add tests in `TestAutojunk` verifying `autojunk` propagation and behavior across `get_close_matches`, `Differ`, `ndiff`, `unified_diff`, `context_diff`, and `HtmlDiff`. * Add signature inspection tests using `inspect.signature` to verify that `autojunk=True` is present and defined as a keyword-only parameter. * Fix passing of `autojunk` as a keyword argument in `difflib._mdiff()` call to `ndiff()`. --- Lib/difflib.py | 2 +- Lib/test/test_difflib.py | 84 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/Lib/difflib.py b/Lib/difflib.py index 0e95d5e9624214..c081cd8606df5b 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -1411,7 +1411,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None, change_re = re.compile(r'(\++|\-+|\^+)') # create the difference iterator to generate the differences - diff_lines_iterator = ndiff(fromlines, tolines, linejunk, charjunk, autojunk) + diff_lines_iterator = ndiff(fromlines, tolines, linejunk, charjunk, autojunk=autojunk) def _make_line(lines, format_key, side, num_lines=[0,0]): """Returns line of text with user's change markup and line formatting. diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py index 4f99b7c91c654e..5babe834e9beac 100644 --- a/Lib/test/test_difflib.py +++ b/Lib/test/test_difflib.py @@ -56,7 +56,7 @@ def test_bjunk(self): class TestAutojunk(unittest.TestCase): - """Tests for the autojunk parameter added in 2.7""" + """Tests for the autojunk parameter added in SequenceMatcher and higher-level difflib APIs""" def test_one_insert_homogenous_sequence(self): # By default autojunk=True and the heuristic kicks in for a sequence # of length 200+ @@ -72,6 +72,88 @@ def test_one_insert_homogenous_sequence(self): self.assertAlmostEqual(sm.ratio(), 0.9975, places=3) self.assertEqual(sm.bpopular, set()) + def test_get_close_matches(self): + word = 'a' + 'b' * 200 + possibilities = ['b' * 200] + + # By default autojunk=True, so 'b' is junk -> ratio ~ 0 -> no matches + self.assertEqual(difflib.get_close_matches(word, possibilities, cutoff=0.6), []) + self.assertEqual(difflib.get_close_matches(word, possibilities, cutoff=0.6, autojunk=True), []) + + # With autojunk=False, ratio ~ 0.9975 -> match returned + self.assertEqual(difflib.get_close_matches(word, possibilities, cutoff=0.6, autojunk=False), ['b' * 200]) + + def test_differ_and_ndiff(self): + lines1 = ["x\n"] * 200 + ["a\n", "b\n", "c\n"] + ["x\n"] * 50 + lines2 = ["a\n", "b\n", "c\n"] + ["x\n"] * 250 + + # Line-level autojunk propagation + d_true = difflib.Differ(autojunk=True) + d_false = difflib.Differ(autojunk=False) + res_true = list(d_true.compare(lines1, lines2)) + res_false = list(d_false.compare(lines1, lines2)) + self.assertNotEqual(res_true, res_false) + + ndiff_true = list(difflib.ndiff(lines1, lines2, autojunk=True)) + ndiff_false = list(difflib.ndiff(lines1, lines2, autojunk=False)) + self.assertNotEqual(ndiff_true, ndiff_false) + self.assertEqual(ndiff_true, res_true) + self.assertEqual(ndiff_false, res_false) + + # Character-level autojunk propagation in Differ (_fancy_replace) + line1 = "x" * 200 + "abc" + "x" * 50 + "\n" + line2 = "abc" + "x" * 250 + "\n" + fancy_true = list(difflib.Differ(autojunk=True).compare([line1], [line2])) + fancy_false = list(difflib.Differ(autojunk=False).compare([line1], [line2])) + self.assertNotEqual(fancy_true, fancy_false) + + def test_unified_and_context_diff(self): + lines1 = ["x\n"] * 200 + ["a\n", "b\n", "c\n"] + ["x\n"] * 50 + lines2 = ["a\n", "b\n", "c\n"] + ["x\n"] * 250 + + u_true = list(difflib.unified_diff(lines1, lines2, autojunk=True)) + u_false = list(difflib.unified_diff(lines1, lines2, autojunk=False)) + self.assertNotEqual(u_true, u_false) + + c_true = list(difflib.context_diff(lines1, lines2, autojunk=True)) + c_false = list(difflib.context_diff(lines1, lines2, autojunk=False)) + self.assertNotEqual(c_true, c_false) + + def test_htmldiff(self): + lines1 = ["x\n"] * 200 + ["a\n", "b\n", "c\n"] + ["x\n"] * 50 + lines2 = ["a\n", "b\n", "c\n"] + ["x\n"] * 250 + + old_prefix = difflib.HtmlDiff._default_prefix + try: + html_true = difflib.HtmlDiff(autojunk=True).make_file(lines1, lines2) + html_false = difflib.HtmlDiff(autojunk=False).make_file(lines1, lines2) + self.assertNotEqual(html_true, html_false) + finally: + difflib.HtmlDiff._default_prefix = old_prefix + + def test_autojunk_signatures(self): + import inspect + + funcs = [ + difflib.get_close_matches, + difflib.unified_diff, + difflib.context_diff, + difflib.ndiff, + ] + for func in funcs: + sig = inspect.signature(func) + self.assertIn('autojunk', sig.parameters) + param = sig.parameters['autojunk'] + self.assertEqual(param.default, True) + self.assertEqual(param.kind, inspect.Parameter.KEYWORD_ONLY) + + for cls in [difflib.Differ, difflib.HtmlDiff]: + sig = inspect.signature(cls.__init__) + self.assertIn('autojunk', sig.parameters) + param = sig.parameters['autojunk'] + self.assertEqual(param.default, True) + + class TestSFbugs(unittest.TestCase): def test_ratio_for_null_seqn(self): From 56204adbafcf8cde3edc15e9d4ddfe5b1ff58031 Mon Sep 17 00:00:00 2001 From: Tomasz Date: Wed, 5 Aug 2026 14:45:43 +0200 Subject: [PATCH 15/18] gh-118150: update difflib doc (#153959) --- Doc/library/difflib.rst | 43 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst index 9c657e9825bee2..63e61e720d0d38 100644 --- a/Doc/library/difflib.rst +++ b/Doc/library/difflib.rst @@ -23,7 +23,7 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. Exposed *autojunk* parameter of :class:`SequenceMatcher` in public functions and classes of this module (:class:`Differ`, :class:`HtmlDiff`, :func:`ndiff`, :func:`unified_diff`, :func:`context_diff`). For backward compatibility - this parameter is set everywhere to be `True` by default. + this parameter is set everywhere to be ``True`` by default. See :gh:`118150` for motivation and reasons. @@ -118,11 +118,10 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. (used by :class:`HtmlDiff` to generate the side by side HTML differences). See :func:`ndiff` documentation for argument default values and descriptions. - .. versionadded:: 3.16 - *autojunk* parameter + .. versionchanged:: 3.16 + Added keyword-only *autojunk* parameter. - Keyword-only *autojunk* flag is for setting on/off automatic junk heuristic - of :class:`SequenceMatcher`. + *autojunk* flag is for setting on/off automatic junk heuristic of :class:`SequenceMatcher`. The following methods are public: @@ -183,11 +182,10 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. For inputs that do not have trailing newlines, set the *lineterm* argument to ``""`` so that the output will be uniformly newline free. - .. versionadded:: 3.16 - *autojunk* kwarg + .. versionchanged:: 3.16 + Added keyword-only *autojunk* parameter. - The kwarg-only parameter *autojunk* sets up automatic junk heuristic of - :class:`SequenceMatcher`. + Optional *autojunk* flag sets on/off automatic junk heuristic of :class:`SequenceMatcher`. The context diff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for *fromfile*, @@ -230,10 +228,10 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. Optional argument *cutoff* (default ``0.6``) is a float in the range [0, 1]. Possibilities that don't score at least that similar to *word* are ignored. - .. versionadded:: 3.16 - *autojunk* parameter + .. versionchanged:: 3.16 + Added keyword-only *autojunk* parameter. - Keyword-only optional *autojunk* param is a flag for turning on/off + Optional *autojunk* param is a flag for turning on/off an automatic junk heuristic of :class:`SequenceMatcher`. The best (no more than *n*) matches among the possibilities are returned in a @@ -271,10 +269,11 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. function :func:`IS_CHARACTER_JUNK`, which filters out whitespace characters (a blank or tab; it's a bad idea to include newline in this!). - .. versionadded:: 3.16 + .. versionchanged:: 3.16 + Added keyword-only *autojunk* parameter. - *autojunk*: keyword-only parameter for setting on/off automatic junk heuristic - of :class:`SequenceMatcher`. + *autojunk*: An optional parameter for setting on/off automatic junk heuristic + of :class:`SequenceMatcher`. Example: @@ -338,13 +337,6 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. :program:`git diff --color`. Even if enabled, it can be :ref:`controlled using environment variables `. - .. versionadded:: 3.16 - - keyword-only *autojunk* parameter. - - Set *autojunk* to ``False`` to disable automatic junk heuristic - of underlying :class:`SequenceMatcher`. - The unified diff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for *fromfile*, *tofile*, *fromfiledate*, and *tofiledate*. The modification times are normally @@ -370,6 +362,13 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module. .. versionchanged:: 3.15 Added the *color* parameter. + .. versionchanged:: 3.16 + Added keyword-only *autojunk* parameter. + + Set *autojunk* to ``False`` in order to disable automatic junk heuristic + of underlying :class:`SequenceMatcher`. + + .. function:: diff_bytes(dfunc, a, b, fromfile=b'', tofile=b'', fromfiledate=b'', tofiledate=b'', n=3, lineterm=b'\n') Compare *a* and *b* (lists of bytes objects) using *dfunc*; yield a From d117379f6b7bc4e48aabf4c897e3d6a9e578a305 Mon Sep 17 00:00:00 2001 From: Tomasz Date: Wed, 5 Aug 2026 15:02:04 +0200 Subject: [PATCH 16/18] gh-118150: update NEWS again --- .../2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst index 169a3c6bb96267..26b68f4bbd0f32 100644 --- a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst +++ b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst @@ -1,9 +1,5 @@ Expose automated junk heuristic kwarg-only flag `autojunk` from :class:`difflib.SequenceMatcher` to the public functions -and class methods in the :mod:`difflib`. This option defaults -to ``True``, meaning that until now it was always implicitly "on" -in other methods and classes of :mod:`difflib` which are relying -on :class:`difflib.SequenceMatcher`. - -See the :class:`difflib.SequenceMatcher` documentation for details -of this flag purpose and issue :gh:`118150` for the motivation. +and class methods in the :mod:`difflib`. +See :class:`difflib.SequenceMatcher` documentation for details +and issue :gh:`118150` for the motivation. From 61e64a2e71d6df47b5457dbbb0a2a85668475f1c Mon Sep 17 00:00:00 2001 From: Tomasz Date: Wed, 5 Aug 2026 15:18:12 +0200 Subject: [PATCH 17/18] gh-118150: fix for sphinx linter --- Doc/whatsnew/3.16.rst | 7 ++++--- .../Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index 4b5201db2e9e2e..bf7bb556761a64 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -260,9 +260,10 @@ ctypes difflib ------- -* Expose *autojunk* parameter from :class:`difflib.SequenceMatcher` in public - functions and class methods which allows to modifty behavior of automatic - junk heuristic in :mod:`difflib`. +* Expose optional ``autojunk`` parameter from :class:`difflib.SequenceMatcher` + to public functions and class methods in :mod:`difflib`, + allowing to modify behavior of automatic junk heuristic in this module + in higher public class methods and functions. (Contributed by Tomasz Kazimierczak in :gh:`118150`) diff --git a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst index 26b68f4bbd0f32..b479302ade4064 100644 --- a/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst +++ b/Misc/NEWS.d/next/Library/2026-07-18-16-43-02.gh-issue-118150.x0mV8P.rst @@ -1,4 +1,4 @@ -Expose automated junk heuristic kwarg-only flag `autojunk` from +Expose automated junk heuristic kwarg-only flag ``autojunk`` from :class:`difflib.SequenceMatcher` to the public functions and class methods in the :mod:`difflib`. See :class:`difflib.SequenceMatcher` documentation for details From c38edf3a953036764e8572fa40158b738db7b211 Mon Sep 17 00:00:00 2001 From: Tomasz Date: Wed, 5 Aug 2026 16:45:05 +0200 Subject: [PATCH 18/18] gh-118150: clean whitespaces for lint --- Doc/library/difflib.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst index 6413bbe00d9d7f..b8bf09a57d2ba8 100644 --- a/Doc/library/difflib.rst +++ b/Doc/library/difflib.rst @@ -34,7 +34,7 @@ of any type, not just text, so long as the sequence elements are See :gh:`118150` for motivation and reasons. - + .. _difflib-junk: Junk heuristic @@ -64,7 +64,7 @@ Depending on your data, you should consider turning this heuristic off or tuning it (using the *isjunk* argument, perhaps to one of the :ref:`predefined functions `). - + The :mod:`!difflib` algorithm -----------------------------