]> granicus.if.org Git - python/commitdiff
SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
authorBrett Cannon <bcannon@gmail.com>
Sat, 10 Jul 2004 23:54:07 +0000 (23:54 +0000)
committerBrett Cannon <bcannon@gmail.com>
Sat, 10 Jul 2004 23:54:07 +0000 (23:54 +0000)
that behaves as if both lists has an empty string in each of them.

Closes bug #979794 (and duplicate bug #980117).

Lib/difflib.py
Lib/test/test_difflib.py
Misc/NEWS

index 529c78638c6b2e54f313f6265a5f91d0b3f6faa1..e82c703a7d875fda158345b30e88ea337f05e12c 100644 (file)
@@ -572,6 +572,8 @@ class SequenceMatcher:
         """
 
         codes = self.get_opcodes()
+        if not codes:
+            codes = [("equal", 0, 1, 0, 1)]
         # Fixup leading and trailing groups if they show no changes.
         if codes[0][0] == 'equal':
             tag, i1, i2, j1, j2 = codes[0]
index 17037547f673180366740c0ffc5d057148cbb1ad..9819c845677f79239892ff606b7b481ca4f8de50 100644 (file)
@@ -12,6 +12,13 @@ class TestSFbugs(unittest.TestCase):
         self.assertEqual(s.quick_ratio(), 1)
         self.assertEqual(s.real_quick_ratio(), 1)
 
+    def test_comparing_empty_lists(self):
+        # Check fix for bug #979794
+        group_gen = difflib.SequenceMatcher(None, [], []).get_grouped_opcodes()
+        self.assertRaises(StopIteration, group_gen.next)
+        diff_gen = difflib.unified_diff([], [])
+        self.assertRaises(StopIteration, diff_gen.next)
+
 Doctests = doctest.DocTestSuite(difflib)
 
 test_support.run_unittest(TestSFbugs, Doctests)
index 73abaa4a203d0d20d903da69964f59ec61619738..507c7a5cd4a327ab51cad24590bddbae4128abda 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,10 @@ Extension modules
 Library
 -------
 
+- Bug #979794: difflib.get_grouped_opcodes() now handles the case of when it is
+  comparing two empty lists.  Was affecting both context_diff() and
+  unified_diff().  Was also a duplicate of bug #980117.
+
 - Bug #980938: smtplib now prints debug output to sys.stderr.
 
 - Bug #930024: posixpath.realpath() now handles infinite loops in symlinks by