jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1345320?usp=email )

Change subject: textlib: Retain only the last timestamp match
......................................................................

textlib: Retain only the last timestamp match

Count regex matches while retaining the rightmost match instead of
building a list of every match in TimeStripper._last_match_and_replace.
This avoids retaining earlier match objects on lines with many matches.

Preserve the no-match result, match positions and replacement behavior,
including the count needed to leave the last two numeric months intact.

Change-Id: I9806c4792fd5b74bb26c8d425f709334e6614346
---
M pywikibot/textlib.py
1 file changed, 5 insertions(+), 5 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index eceb10b..1a34f97 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -2326,14 +2326,14 @@

         It does so to prevent spurious earlier matches.
         """
-        all_matches = list(pat.finditer(txt))
-        cnt = len(all_matches)
+        cnt = 0
+        m = None
+        for m in pat.finditer(txt):
+            cnt += 1

-        if not cnt:
+        if m is None:
             return (txt, None)

-        m = all_matches[-1]
-
         def marker(m: re.Match[str]):
             """Replace exactly the same number of matched characters.


--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1345320?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: I9806c4792fd5b74bb26c8d425f709334e6614346
Gerrit-Change-Number: 1345320
Gerrit-PatchSet: 2
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