[ python-Bugs-980117 ] Index error for empty lists in Difflib

SourceForge.net noreply at sourceforge.net
Sun Jul 11 01:55:51 CEST 2004


Bugs item #980117, was opened at 2004-06-25 19:41
Message generated for change (Comment added) made by bcannon
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=980117&group_id=5470

Category: Python Library
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Rocco Moretti (roccomoretti)
Assigned to: Nobody/Anonymous (nobody)
Summary: Index error for empty lists in Difflib

Initial Comment:
When using the context_diff and unified_diff functions
in difflib, submitting two empty lists to compare to
each other produces an IndexError, as opposed to the
expected empty diff. This error does not occur when
using ndiff, or when comparing a nonempty list to an
empty list. (In either direction)

<See patch manager for a potential fix.>

Example Behavior:

Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for
more information.
>>> import difflib
>>> difflib.unified_diff([],[])
<generator object at 0x008E0918>
>>> list(difflib.unified_diff([],[]))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Python23\lib\difflib.py", line 1149, in
unified_diff
    for group in
SequenceMatcher(None,a,b).get_grouped_opcodes(n):
  File "C:\Python23\lib\difflib.py", line 574, in
get_grouped_opcodes
    if codes[0][0] == 'equal':
IndexError: list index out of range
>>> list(difflib.unified_diff([],['']))
['---  \n', '+++  \n', '@@ -1,0 +1,1 @@\n', '+']
>>> list(difflib.unified_diff([''],[]))
['---  \n', '+++  \n', '@@ -1,1 +1,0 @@\n', '-']
>>>


----------------------------------------------------------------------

>Comment By: Brett Cannon (bcannon)
Date: 2004-07-10 16:55

Message:
Logged In: YES 
user_id=357491

Fixed in rev. 1.21.  Not being backported in case someone actually 
expects this behavior.

----------------------------------------------------------------------

Comment By: Barry A. Warsaw (bwarsaw)
Date: 2004-06-25 20:18

Message:
Logged In: YES 
user_id=12800

Probably a dup of 979794


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=980117&group_id=5470


More information about the Python-bugs-list mailing list