jenkins-bot merged this change.

View Change

Approvals: Matěj Suchánek: Looks good to me, but someone else must approve Dvorapa: Looks good to me, but someone else must approve Huji: Looks good to me, approved jenkins-bot: Verified
[bugfix] compare whether tag is equal to string constant

- compare whether tag is equal to string constant in create_diff
instead tag is _in_ string. Otherwise that check could fail if
tag is a substring
- use elif to compare different tags
- simplify check_line

Change-Id: Ifb3b67703d0f3aee235be617d1e2324f5ae0c231
---
M pywikibot/diff.py
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/pywikibot/diff.py b/pywikibot/diff.py
index 1bc9a20..a309aed 100644
--- a/pywikibot/diff.py
+++ b/pywikibot/diff.py
@@ -90,9 +90,7 @@
# make sure each line ends with '\n' to prevent
# behaviour like http://bugs.python.org/issue2142
def check_line(line):
- if not line.endswith('\n'):
- line += '\n'
- return line
+ return line if line.endswith('\n') else line + '\n'

for tag, i1, i2, j1, j2 in self.group:
# equal/delete/insert add additional space after the sign as it's
@@ -100,13 +98,13 @@
if tag == 'equal':
for line in self.a[i1:i2]:
yield ' ' + check_line(line)
- if tag in ('delete'):
+ elif tag == 'delete':
for line in self.a[i1:i2]:
yield '- ' + check_line(line)
- if tag in ('insert'):
+ elif tag == 'insert':
for line in self.b[j1:j2]:
yield '+ ' + check_line(line)
- if tag in ('replace'):
+ elif tag == 'replace':
for line in difflib.ndiff(self.a[i1:i2], self.b[j1:j2]):
yield check_line(line)


To view, visit change 584896. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifb3b67703d0f3aee235be617d1e2324f5ae0c231
Gerrit-Change-Number: 584896
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Huji <huji.huji@gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: Mpaa <mpaa.wiki@gmail.com>