Hello there,
showDiff throws an IndexError if used on texts with no difference but a non-zero context. Since this is not documented, I think this is a bug.
I can reproduce the bug with the latest git code (f2daf078):
$ python3 Python 3.7.7 (default, Mar 10 2020, 15:43:33) [Clang 11.0.0 (clang-1100.0.33.17)] on darwin Type "help", "copyright", "credits" or "license" for more information.
>>> import pywikibot
>>> pywikibot.showDiff("foo", "foo", context=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/private/tmp/pywikibot/pywikibot/__init__.py", line 1314, in showDiff
PatchManager(oldtext, newtext, context=context).print_hunks()
File "/private/tmp/pywikibot/pywikibot/tools/__init__.py", line 1797, in wrapper
return obj(*__args, **__kw)
File "/private/tmp/pywikibot/pywikibot/diff.py", line 300, in __init__
self._super_hunks = self._generate_super_hunks()
File "/private/tmp/pywikibot/pywikibot/diff.py", line 361, in _generate_super_hunks
return [_SuperHunk(sh) for sh in super_hunks]
File "/private/tmp/pywikibot/pywikibot/diff.py", line 361, in <listcomp>
return [_SuperHunk(sh) for sh in super_hunks]
File "/private/tmp/pywikibot/pywikibot/diff.py", line 223, in __init__
self.a_rng = (self._hunks[0].a_rng[0], self._hunks[-1].a_rng[1])
IndexError: list index out of rangeNote: the length of the text doesn’t matter:
>>> text = "foobar\n" * 100
>>> pywikibot.showDiff(text, text, context=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/private/tmp/pywikibot/pywikibot/__init__.py", line 1314, in showDiff
PatchManager(oldtext, newtext, context=context).print_hunks()
File "/private/tmp/pywikibot/pywikibot/tools/__init__.py", line 1797, in wrapper
return obj(*__args, **__kw)
File "/private/tmp/pywikibot/pywikibot/diff.py", line 300, in __init__
self._super_hunks = self._generate_super_hunks()
File "/private/tmp/pywikibot/pywikibot/diff.py", line 361, in _generate_super_hunks
return [_SuperHunk(sh) for sh in super_hunks]
File "/private/tmp/pywikibot/pywikibot/diff.py", line 361, in <listcomp>
return [_SuperHunk(sh) for sh in super_hunks]
File "/private/tmp/pywikibot/pywikibot/diff.py", line 223, in __init__
self.a_rng = (self._hunks[0].a_rng[0], self._hunks[-1].a_rng[1])
IndexError: list index out of rangeExpected output: pywikibot.showDiff("foo", "foo", context=2) should print nothing, just like pywikibot.showDiff("foo", "foo") does.
Actual output: see above.