@@ -733,20 +733,15 @@ def get_close_matches(word, possibilities, n=3, cutoff=0.6):
733733 # Strip scores for the best n matches
734734 return [x for score , x in result ]
735735
736- def _count_leading (line , ch ):
737- """
738- Return number of `ch` characters at the start of `line`.
739736
740- Example:
737+ def _keep_original_ws (s , tag_s ):
738+ """Replace whitespace with the original whitespace characters in `s`"""
739+ return '' .join (
740+ c if tag_c == " " and c .isspace () else tag_c
741+ for c , tag_c in zip (s , tag_s )
742+ )
741743
742- >>> _count_leading(' abc', ' ')
743- 3
744- """
745744
746- i , n = 0 , len (line )
747- while i < n and line [i ] == ch :
748- i += 1
749- return i
750745
751746class Differ :
752747 r"""
@@ -1033,7 +1028,7 @@ def _fancy_helper(self, a, alo, ahi, b, blo, bhi):
10331028
10341029 def _qformat (self , aline , bline , atags , btags ):
10351030 r"""
1036- Format "?" output and deal with leading tabs.
1031+ Format "?" output and deal with tabs.
10371032
10381033 Example:
10391034
@@ -1047,22 +1042,16 @@ def _qformat(self, aline, bline, atags, btags):
10471042 '+ \tabcdefGhijkl\n'
10481043 '? \t ^ ^ ^\n'
10491044 """
1050-
1051- # Can hurt, but will probably help most of the time.
1052- common = min (_count_leading (aline , "\t " ),
1053- _count_leading (bline , "\t " ))
1054- common = min (common , _count_leading (atags [:common ], " " ))
1055- common = min (common , _count_leading (btags [:common ], " " ))
1056- atags = atags [common :].rstrip ()
1057- btags = btags [common :].rstrip ()
1045+ atags = _keep_original_ws (aline , atags ).rstrip ()
1046+ btags = _keep_original_ws (bline , btags ).rstrip ()
10581047
10591048 yield "- " + aline
10601049 if atags :
1061- yield "? %s%s \n " % ( " \t " * common , atags )
1050+ yield f "? { atags } \n "
10621051
10631052 yield "+ " + bline
10641053 if btags :
1065- yield "? %s%s \n " % ( " \t " * common , btags )
1054+ yield f "? { btags } \n "
10661055
10671056# With respect to junk, an earlier version of ndiff simply refused to
10681057# *start* a match with a junk element. The result was cases like this:
@@ -1085,7 +1074,7 @@ def _qformat(self, aline, bline, atags, btags):
10851074
10861075def IS_LINE_JUNK (line , pat = re .compile (r"\s*(?:#\s*)?$" ).match ):
10871076 r"""
1088- Return 1 for ignorable line: iff `line` is blank or contains a single '#'.
1077+ Return True for ignorable line: iff `line` is blank or contains a single '#'.
10891078
10901079 Examples:
10911080
@@ -1101,7 +1090,7 @@ def IS_LINE_JUNK(line, pat=re.compile(r"\s*(?:#\s*)?$").match):
11011090
11021091def IS_CHARACTER_JUNK (ch , ws = " \t " ):
11031092 r"""
1104- Return 1 for ignorable character: iff `ch` is a space or tab.
1093+ Return True for ignorable character: iff `ch` is a space or tab.
11051094
11061095 Examples:
11071096
0 commit comments