Skip to content

Commit aae1de3

Browse files
committed
doc fixes
1 parent 79eb2f7 commit aae1de3

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

Doc/library/difflib.rst

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,21 @@ The :class:`SequenceMatcherBase` class has this constructor:
461461
Set the second sequence to be compared. The first sequence to be compared
462462
is not changed.
463463

464+
.. method:: _get_matching_blocks()
465+
:abstractmethod:
466+
467+
Returns list of tuples of the form ``(start_in_a, start_in_b, length)``
468+
describing matching subsequences.
469+
470+
Validity of whether blocks actually match is not checked
471+
and it is up to the user to make sure of result's correctness.
472+
473+
This method implements the core matching logic, while
474+
:meth:`get_matching_blocks` takes care of the maintenance and caching.
475+
476+
For custom maintenance and caching, :meth:`get_matching_blocks` can be
477+
overriden by derived class without making use of this method.
478+
464479
.. method:: get_matching_blocks()
465480

466481
Return list of triples describing non-overlapping matching subsequences.
@@ -580,8 +595,8 @@ The :class:`SequenceMatcherBase` class has this constructor:
580595

581596
The three methods that return the ratio of matching to total characters can give
582597
different results due to differing levels of approximation, although
583-
:meth:`~SequenceMatcher.quick_ratio` and :meth:`~SequenceMatcher.real_quick_ratio`
584-
are always at least as large as :meth:`~SequenceMatcher.ratio`:
598+
:meth:`~SequenceMatcherBase.quick_ratio` and :meth:`~SequenceMatcherBase.real_quick_ratio`
599+
are always at least as large as :meth:`~SequenceMatcherBase.ratio`:
585600

586601
>>> s = SequenceMatcher(None, "abcd", "bcde")
587602
>>> s.ratio()
@@ -620,8 +635,9 @@ The :class:`SequenceMatcher` class has this constructor:
620635

621636
:class:`SequenceMatcher` computes and caches detailed information about the
622637
second sequence, so if you want to compare one sequence against many
623-
sequences, use :meth:`set_seq2` to set the commonly used sequence once and
624-
call :meth:`set_seq1` repeatedly, once for each of the other sequences.
638+
sequences, use :meth:`~SequenceMatcherBase.set_seq2` to set the commonly used
639+
sequence once and call :meth:`~SequenceMatcherBase.set_seq1` repeatedly,
640+
once for each of the other sequences.
625641

626642
In addition to methods implemented by :class:`SequenceMatcherBase`,
627643
:class:`SequenceMatcher` objects have the following methods:
@@ -684,9 +700,9 @@ This example compares two strings, considering blanks to be "junk":
684700
... "private Thread currentThread;",
685701
... "private volatile Thread currentThread;")
686702

687-
:meth:`~SequenceMatcher.ratio` returns a float in [0, 1], measuring the similarity of the
688-
sequences. As a rule of thumb, a :meth:`~SequenceMatcher.ratio` value over 0.6 means the
689-
sequences are close matches:
703+
:meth:`~SequenceMatcherBase.ratio` returns a float in [0, 1], measuring
704+
the similarity of the sequences. As a rule of thumb, a :meth:`~SequenceMatcherBase.ratio`
705+
value over 0.6 means the sequences are close matches:
690706

691707
>>> print(round(s.ratio(), 3))
692708
0.866
@@ -700,12 +716,12 @@ If you're only interested in where the sequences match,
700716
a[8] and b[17] match for 21 elements
701717
a[29] and b[38] match for 0 elements
702718

703-
Note that the last tuple returned by :meth:`~SequenceMatcher.get_matching_blocks`
719+
Note that the last tuple returned by :meth:`~SequenceMatcherBase.get_matching_blocks`
704720
is always a dummy, ``(len(a), len(b), 0)``, and this is the only case in which the last
705721
tuple element (number of elements matched) is ``0``.
706722

707723
If you want to know how to change the first sequence into the second, use
708-
:meth:`~SequenceMatcher.get_opcodes`:
724+
:meth:`~SequenceMatcherBase.get_opcodes`:
709725

710726
>>> for opcode in s.get_opcodes():
711727
... print("%6s a[%d:%d] b[%d:%d]" % opcode)

Lib/difflib.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,17 @@ def _prepare_seq2(self):
241241
# ---------------------------------
242242

243243
def _get_matching_blocks(self):
244-
"""Return list of triples describing matching subsequences.
244+
"""Returns list of tuples of the form (start_in_a, start_in_b, length)
245+
describing matching subsequences.
246+
247+
Validity of whether blocks actually match is not checked
248+
and it is up to the user to make sure of result's correctness.
245249
246-
Implement this to return list[tuple[int, int, int]] and
247-
let `get_matching_blocks` take care of maintenance and caching
250+
This method implements the core matching logic, while
251+
`get_matching_blocks` takes care of the maintenance and caching.
248252
249-
Note, that validity of whether blocks actually match is not checked
250-
and it is up to the user to make sure of correctness of the result.
253+
For custom maintenance and caching, get_matching_blocks can be
254+
overriden by derived class without making use of this method.
251255
"""
252256
raise NotImplementedError
253257

0 commit comments

Comments
 (0)