Skip to content

Commit dd33cde

Browse files
committed
typos and minor doc improvements
1 parent 8077fd1 commit dd33cde

2 files changed

Lines changed: 35 additions & 35 deletions

File tree

Doc/library/difflib.rst

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
--------------
1515

1616
This module provides classes and functions for comparing sequences. It
17-
can be used for example, for comparing files, and can produce information
17+
can be used, for example, for comparing files, and can produce information
1818
about file differences in various formats, including HTML and context and unified
19-
diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
19+
diffs. For comparing directories and files, see the :mod:`filecmp` module.
2020

2121

2222
.. class:: SequenceMatcherBase
@@ -25,16 +25,17 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
2525
Base class for implementing sequence matchers.
2626

2727
At minimum, derived classes must implement ``_get_matching_blocks`` method,
28-
which returns a list of blocks tuple[start_in_a, start_in_b, length].
29-
See ``_get_matching_blocks`` and ``get_matching_blocks`` for more information.
30-
31-
Once implemented, the following methods make use of it and are available:
32-
:meth:`~SequenceMatcherBase.get_matching_blocks`
33-
:meth:`~SequenceMatcherBase.get_opcodes`
34-
:meth:`~SequenceMatcherBase.get_grouped_opcodes`
35-
:meth:`~SequenceMatcherBase.ratio`
36-
:meth:`~SequenceMatcherBase.quick_ratio`
37-
:meth:`~SequenceMatcherBase.real_quick_ratio`
28+
which returns a list of tuples of the form ``(start_in_a, start_in_b, length)``.
29+
See :meth:`~SequenceMatcherBase._get_matching_blocks` and
30+
:meth:`~SequenceMatcherBase.get_matching_blocks` for more information.
31+
32+
Once implemented, the following methods are available:
33+
- :meth:`~SequenceMatcherBase.get_matching_blocks`
34+
- :meth:`~SequenceMatcherBase.get_opcodes`
35+
- :meth:`~SequenceMatcherBase.get_grouped_opcodes`
36+
- :meth:`~SequenceMatcherBase.ratio`
37+
- :meth:`~SequenceMatcherBase.quick_ratio`
38+
- :meth:`~SequenceMatcherBase.real_quick_ratio`
3839

3940
See :class:`SequenceMatcher` for example implementation.
4041

@@ -272,7 +273,7 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
272273
usually works better than using this function.
273274

274275
*charjunk*: A function that accepts a character (a string of length 1), and
275-
returns if the character is junk, or false if not. The default is module-level
276+
returns true if the character is junk, or false if not. The default is module-level
276277
function :func:`IS_CHARACTER_JUNK`, which filters out whitespace characters (a
277278
blank or tab; it's a bad idea to include newline in this!).
278279

@@ -444,10 +445,10 @@ The :class:`SequenceMatcherBase` class has this constructor:
444445

445446
Set the two sequences to be compared.
446447

447-
:class:`SequenceMatcherBase` inends to cache detailed information about the
448+
:class:`SequenceMatcherBase` caches detailed information about the
448449
second sequence. :meth:`set_seq2` clears cache of :meth:`quick_ratio` method.
449450
In addition :meth:`_prepare_seq2`, which is called at the end of :meth:`set_seq2`,
450-
can be implemented by derrived class for alignment algorithm cache logic.
451+
can be implemented by derived class for alignment algorithm cache logic.
451452

452453
.. method:: set_seq1(a)
453454

@@ -460,7 +461,7 @@ The :class:`SequenceMatcherBase` class has this constructor:
460461
Set the second sequence to be compared. The first sequence to be compared
461462
is not changed.
462463

463-
.. method:: get_matching_blocks()
464+
.. method:: get_matching_blocks()
464465

465466
Return list of triples describing non-overlapping matching subsequences.
466467
Each triple is of the form ``(i, j, n)``,
@@ -486,7 +487,7 @@ The :class:`SequenceMatcherBase` class has this constructor:
486487

487488
Preparation method that is called at the end of :meth:`set_seq2`.
488489

489-
By default it does nothing, but can be implemented by derrived class
490+
By default it does nothing, but can be implemented by derived class
490491
for alignment algorithm cache logic.
491492

492493

Lib/difflib.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,16 @@ class SequenceMatcherBase:
114114
"""Base class for implementing sequence matchers.
115115
116116
At minimum, derived classes must implement `_get_matching_blocks` method,
117-
which returns a list of blocks tuple[start_in_a, start_in_b, length].
117+
which returns a list of tuples of the form (start_in_a, start_in_b, length).
118118
See `_get_matching_blocks` and `get_matching_blocks` for more information.
119119
120-
Once implemented, the following methods make use of it and are available:
121-
get_matching_blocks
122-
get_opcodes
123-
get_grouped_opcodes
124-
ratio
125-
quick_ratio
126-
real_quick_ratio
120+
Once implemented, the following methods are available:
121+
- get_matching_blocks
122+
- get_opcodes
123+
- get_grouped_opcodes
124+
- ratio
125+
- quick_ratio
126+
- real_quick_ratio
127127
128128
See `SequenceMatcher` for example implementation.
129129
"""
@@ -217,10 +217,10 @@ def set_seq2(self, b):
217217
1.0
218218
>>>
219219
220-
SequenceMatcherBase inends to cache detailed information about the
220+
SequenceMatcherBase caches detailed information about the
221221
second sequence. set_seq2 clears cache of quick_ratio method.
222222
In addition _prepare_seq2, which is called at the end of set_seq2,
223-
can be implemented by derrived class for alignment algorithm cache logic.
223+
can be implemented by derived class for alignment algorithm cache logic.
224224
225225
See also set_seqs() and set_seq1().
226226
"""
@@ -235,7 +235,7 @@ def set_seq2(self, b):
235235
def _prepare_seq2(self):
236236
"""Preparation method that is called at the end of `set_seq2`.
237237
238-
By default it does nothing, but can be implemented by derrived class
238+
By default it does nothing, but can be implemented by derived class
239239
for alignment algorithm cache logic.
240240
"""
241241
pass
@@ -688,7 +688,8 @@ def find_longest_match(self, alo=0, ahi=None, blo=0, bhi=None):
688688
# Windiff ends up at the same place as diff, but by pairing up
689689
# the unique 'b's and then matching the first two 'a's.
690690

691-
a, b, b2j, bjunk = self.a, self.b, self.b2j, self.bjunk
691+
a, b, b2j = self.a, self.b, self.b2j
692+
bjunk, bpopular = self.bjunk, self.bpopular
692693
if ahi is None:
693694
ahi = len(a)
694695
if bhi is None:
@@ -716,13 +717,12 @@ def find_longest_match(self, alo=0, ahi=None, blo=0, bhi=None):
716717
j2len = newj2len
717718

718719
block = besti, bestj, bestsize
719-
if self.autojunk:
720+
if bpopular:
720721
# Extend the best by non-junk elements on each end. In particular,
721722
# "popular" non-junk elements aren't in b2j, which greatly speeds
722723
# the inner loop above, but also means "the best" match so far
723724
# doesn't contain any junk *or* popular non-junk elements.
724-
block = _expand_block_to_junk(
725-
bjunk, block, a, b, alo, ahi, blo, bhi, inverse=True)
725+
block = _expand_block_to_junk(bpopular, block, a, b, alo, ahi, blo, bhi)
726726

727727
if bjunk:
728728
# Now that we have a wholly interesting match (albeit possibly
@@ -732,8 +732,7 @@ def find_longest_match(self, alo=0, ahi=None, blo=0, bhi=None):
732732
# figuring out what to do with it. In the case of an empty
733733
# interesting match, this is clearly the right thing to do,
734734
# because no other kind of match is possible in the regions.
735-
block = _expand_block_to_junk(
736-
bjunk, block, a, b, alo, ahi, blo, bhi, inverse=False)
735+
block = _expand_block_to_junk(bjunk, block, a, b, alo, ahi, blo, bhi)
737736

738737
return Match._make(block)
739738

@@ -1478,7 +1477,7 @@ def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK, differ=None):
14781477
functions, or can be None:
14791478
14801479
- linejunk: A function that should accept a single string argument and
1481-
return true iff the string is junk. The default is None, and is
1480+
returns true iff the string is junk. The default is None, and is
14821481
recommended; the underlying SequenceMatcher class has an adaptive
14831482
notion of "noise" lines.
14841483

0 commit comments

Comments
 (0)