Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bcd8988

Browse files
committed
Issue 10534 deprecate isbjunk and isbpopular methods.
Will add gone in 3.3 test later.
1 parent 3a11e71 commit bcd8988

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

Lib/difflib.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
'Differ','IS_CHARACTER_JUNK', 'IS_LINE_JUNK', 'context_diff',
3333
'unified_diff', 'HtmlDiff', 'Match']
3434

35+
import warnings
3536
import heapq
3637
from collections import namedtuple as _namedtuple
3738

@@ -182,7 +183,7 @@ def __init__(self, isjunk=None, a='', b='', autojunk=True):
182183
# we need to do to 'a' to change it into 'b'?"
183184
# b2j
184185
# for x in b, b2j[x] is a list of the indices (into b)
185-
# at which x appears; junk elements do not appear
186+
# at which x appears; junk and popular elements do not appear
186187
# fullbcount
187188
# for x in b, fullbcount[x] == the number of times x
188189
# appears in b; only materialized if really needed (used
@@ -204,15 +205,6 @@ def __init__(self, isjunk=None, a='', b='', autojunk=True):
204205
# subtle but helpful effects on the algorithm, which I'll
205206
# get around to writing up someday <0.9 wink>.
206207
# DON'T USE! Only __chain_b uses this. Use isbjunk.
207-
# isbjunk
208-
# for x in b, isbjunk(x) == isjunk(x) but much faster;
209-
# it's really the __contains__ method of a hidden dict.
210-
# DOES NOT WORK for x in a!
211-
# isbpopular
212-
# for x in b, isbpopular(x) is true iff b is reasonably long
213-
# (at least 200 elements) and x accounts for more than 1 + 1% of
214-
# its elements (when autojunk is enabled).
215-
# DOES NOT WORK for x in a!
216208
# bjunk
217209
# the items in b for which isjunk is True.
218210
# bpopular
@@ -343,12 +335,19 @@ def __chain_b(self):
343335
popular.add(elt)
344336
del b2j[elt]
345337

346-
# Now for x in b, isjunk(x) == x in junk, but the latter is much faster.
347-
# Since the number of *unique* junk elements is probably small, the
348-
# memory burden of keeping this set alive is likely trivial compared to
349-
# the size of b2j.
350-
self.isbjunk = junk.__contains__
351-
self.isbpopular = popular.__contains__
338+
def isbjunk(self, item):
339+
"Deprecated; use 'item in SequenceMatcher().bjunk'."
340+
warnings.warn("'SequenceMatcher().isbjunk(item)' is deprecated;\n"
341+
"use 'item in SMinstance.bjunk' instead.",
342+
DeprecationWarning, 2)
343+
return item in self.bjunk
344+
345+
def isbpopular(self, item):
346+
"Deprecated; use 'item in SequenceMatcher().bpopular'."
347+
warnings.warn("'SequenceMatcher().isbpopular(item)' is deprecated;\n"
348+
"use 'item in SMinstance.bpopular' instead.",
349+
DeprecationWarning, 2)
350+
return item in self.bpopular
352351

353352
def find_longest_match(self, alo, ahi, blo, bhi):
354353
"""Find longest matching block in a[alo:ahi] and b[blo:bhi].
@@ -406,7 +405,7 @@ def find_longest_match(self, alo, ahi, blo, bhi):
406405
# Windiff ends up at the same place as diff, but by pairing up
407406
# the unique 'b's and then matching the first two 'a's.
408407

409-
a, b, b2j, isbjunk = self.a, self.b, self.b2j, self.isbjunk
408+
a, b, b2j, isbjunk = self.a, self.b, self.b2j, self.bjunk.__contains__
410409
besti, bestj, bestsize = alo, blo, 0
411410
# find longest junk-free match
412411
# during an iteration of the loop, j2len[j] = length of longest

0 commit comments

Comments
 (0)