From 1c5718d864d3b5f6f3d76bcb74468fc607735edb Mon Sep 17 00:00:00 2001 From: Liam Ferris Date: Thu, 7 Nov 2019 16:11:37 +0000 Subject: [PATCH] autojunk parameter added to ndiff method and to Differ class so that autojunking can be turned on or off when calling ndiff. Using default value similar to SequenceMatcher --- Lib/difflib.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Lib/difflib.py b/Lib/difflib.py index 3de1b3d0fcdfee..7c0c30e7090f50 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -837,7 +837,7 @@ class Differ: Compare two sequences of lines; generate the resulting delta. """ - def __init__(self, linejunk=None, charjunk=None): + def __init__(self, linejunk=None, charjunk=None, autojunk=True): """ Construct a text differencer, with optional filters. @@ -859,6 +859,7 @@ def __init__(self, linejunk=None, charjunk=None): self.linejunk = linejunk self.charjunk = charjunk + self.autojunk = autojunk def compare(self, a, b): r""" @@ -886,7 +887,7 @@ def compare(self, a, b): + emu """ - cruncher = SequenceMatcher(self.linejunk, a, b) + cruncher = SequenceMatcher(self.linejunk, a, b, 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) @@ -1330,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. @@ -1365,7 +1366,7 @@ 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):