aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlrjball <50599110+lrjball@users.noreply.github.com>2020-04-30 04:42:45 +0100
committerGitHub <noreply@github.com>2020-04-29 22:42:45 -0500
commit3209cbd99b6d65aa18b3beb124fac9c792b8993d (patch)
treefafcfaccc30732b2e50094ad967940ef1e66c401 /Lib/difflib.py
parentbpo-40443: Remove unused imports in idlelib (GH-19801) (diff)
downloadcpython-3209cbd99b6d65aa18b3beb124fac9c792b8993d.tar.gz
cpython-3209cbd99b6d65aa18b3beb124fac9c792b8993d.tar.bz2
cpython-3209cbd99b6d65aa18b3beb124fac9c792b8993d.zip
bpo-40394 - difflib.SequenceMatched.find_longest_match default args (GH-19742)
* bpo-40394 - difflib.SequenceMatched.find_longest_match default args Added default args to find_longest_match, as well as related tests.
Diffstat (limited to 'Lib/difflib.py')
-rw-r--r--Lib/difflib.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/difflib.py b/Lib/difflib.py
index f2215d8d456..0dda80d3875 100644
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -130,7 +130,7 @@ class SequenceMatcher:
set_seq2(b)
Set the second sequence to be compared.
- find_longest_match(alo, ahi, blo, bhi)
+ find_longest_match(alo=0, ahi=None, blo=0, bhi=None)
Find longest matching block in a[alo:ahi] and b[blo:bhi].
get_matching_blocks()
@@ -334,9 +334,11 @@ class SequenceMatcher:
for elt in popular: # ditto; as fast for 1% deletion
del b2j[elt]
- def find_longest_match(self, alo, ahi, blo, bhi):
+ def find_longest_match(self, alo=0, ahi=None, blo=0, bhi=None):
"""Find longest matching block in a[alo:ahi] and b[blo:bhi].
+ By default it will find the longest match in the entirety of a and b.
+
If isjunk is not defined:
Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
@@ -391,6 +393,10 @@ class SequenceMatcher:
# the unique 'b's and then matching the first two 'a's.
a, b, b2j, isbjunk = self.a, self.b, self.b2j, self.bjunk.__contains__
+ if ahi is None:
+ ahi = len(a)
+ if bhi is None:
+ bhi = len(b)
besti, bestj, bestsize = alo, blo, 0
# find longest junk-free match
# during an iteration of the loop, j2len[j] = length of longest