Skip to content
7 changes: 2 additions & 5 deletions Lib/difflib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,9 +1038,7 @@ def _qformat(self, aline, bline, atags, btags):
# remaining is that perhaps it was really the case that " volatile"
# was inserted after "private". I can live with that <wink>.

import re

def IS_LINE_JUNK(line, pat=re.compile(r"\s*(?:#\s*)?$").match):
def IS_LINE_JUNK(line, pat=None):
r"""
Return True for ignorable line: iff `line` is blank or contains a single '#'.

Expand All @@ -1054,7 +1052,7 @@ def IS_LINE_JUNK(line, pat=re.compile(r"\s*(?:#\s*)?$").match):
False
"""

return pat(line) is not None
return line.strip() in ('', '#')

def IS_CHARACTER_JUNK(ch, ws=" \t"):
r"""
Expand Down Expand Up @@ -2027,7 +2025,6 @@ def make_table(self,fromlines,tolines,fromdesc='',todesc='',context=False,
replace('\1','</span>'). \
replace('\t','&nbsp;')

del re

def restore(delta, which):
r"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve speed of :func:`difflib.IS_LINE_JUNK` by replacing :mod:`re` with
built-in string methods.
Loading