FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-2986: Allow disabling difflib's automatic junk heuristic by liamFerris · Pull Request #17082 · python/cpython · GitHub

Repository navigation

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 5 additions & 4 deletions Lib/difflib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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):
Expand Down

Back | FazBrowse Home | New Git URL