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

SourceForge.net noreply at sourceforge.net
Fri Jun 25 22:41:30 EDT 2004


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

Category: Python Library
Group: None
Status: Open
Resolution: None
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', '-']
>>>


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

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