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

Change subject: textlib: Retain only last category match
......................................................................

textlib: Retain only last category match

replaceCategoryLinks only uses the final category match but stores every match 
in a list.

Use a bounded deque to retain the last match while consuming the iterator.

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

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




diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index de11830..81647be 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -9,7 +9,7 @@
 import itertools
 import re
 import sys
-from collections import OrderedDict
+from collections import OrderedDict, deque
 from collections.abc import Callable, Container, Iterable, Mapping, Sequence
 from contextlib import closing, suppress
 from dataclasses import dataclass
@@ -1929,7 +1929,7 @@

     if under_categories:
         category = get_regexes('category', site)[0]
-        last_category = list(category.finditer(newtext))[-1]
+        last_category = deque(category.finditer(newtext), maxlen=1)[0]
         for reg in under_categories:
             special = reg.search(newtext)
             if special and not isDisabled(newtext, special.start()):

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