Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1323963?usp=email )

Change subject: diff: Simplify trailing newline removal
......................................................................

diff: Simplify trailing newline removal

Use str.removesuffix() to remove a trailing newline from the hunk list without 
conditional slicing.

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

Approvals:
  Xqt: Verified; Looks good to me, approved




diff --git a/pywikibot/diff.py b/pywikibot/diff.py
index 5aaacb8..014c10f 100644
--- a/pywikibot/diff.py
+++ b/pywikibot/diff.py
@@ -497,15 +497,13 @@
                                  + str(int(math.log10(len(super_hunks)) + 1))
                                  + '}: {3: <' + str(rng_width) + '} {4}{5}')
                 # the last entry is the first changed line which usually ends
-                # with a \n (only the last may not, which is covered by the
-                # if-condition following this block)
+                # with a \n; only the last may not
                 hunk_list_str = ''.join(
                     line_template.format(
                         '*' if hunk_entry[1] == position + 1 else
                         ' ', *hunk_entry)
                     for hunk_entry in hunk_list)
-                if hunk_list_str.endswith('\n'):
-                    hunk_list_str = hunk_list_str[:-1]
+                hunk_list_str = hunk_list_str.removesuffix('\n')
                 pywikibot.info(hunk_list_str)
                 next_hunk = pywikibot.input('Go to which hunk?')
                 try:

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1323963?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I100ae496bb58f78ca63e68d4a6930babb0d38de5
Gerrit-Change-Number: 1323963
Gerrit-PatchSet: 1
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to