jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/822044 )

Change subject: Revert pairwise usage in several scripts
......................................................................

Revert pairwise usage in several scripts

pairwise is overlapping which is not appropriate in these cases.

This partly reverts commit d4ab3d26ae476983cbd38829b711ceaa19aaf75b.

Change-Id: I938f703408a161f0d4f7b803c0ae0ab418a1f76c
---
M scripts/claimit.py
M scripts/replace.py
M scripts/template.py
3 files changed, 18 insertions(+), 18 deletions(-)

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



diff --git a/scripts/claimit.py b/scripts/claimit.py
index 4fff795..3e1ac09 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -52,7 +52,6 @@
 #
 import pywikibot
 from pywikibot import WikidataBot, pagegenerators
-from pywikibot.backports import pairwise


 # This is required for the text that is shown when you run this script
@@ -127,15 +126,15 @@

     claims = []
     repo = pywikibot.Site().data_repository()
-    for source_str, target_str in pairwise(commandline_claims):
-        claim = pywikibot.Claim(repo, source_str)
+    for i in range(0, len(commandline_claims), 2):
+        claim = pywikibot.Claim(repo, commandline_claims[i])
         if claim.type == 'wikibase-item':
-            target = pywikibot.ItemPage(repo, target_str)
+            target = pywikibot.ItemPage(repo, commandline_claims[i + 1])
         elif claim.type == 'string':
-            target = target_str
+            target = commandline_claims[i + 1]
         elif claim.type == 'globe-coordinate':
             coord_args = [
-                float(c) for c in target_str.split(',')]
+                float(c) for c in commandline_claims[i + 1].split(',')]
             if len(coord_args) >= 3:
                 precision = coord_args[2]
             else:
diff --git a/scripts/replace.py b/scripts/replace.py
index 703dd5c..ac97270 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -154,7 +154,7 @@

 import pywikibot
 from pywikibot import editor, fixes, i18n, pagegenerators, textlib
-from pywikibot.backports import pairwise, Dict, Generator, List, Pattern, Tuple
+from pywikibot.backports import Dict, Generator, List, Pattern, Tuple
 from pywikibot.bot import ExistingPageBot, SingleSiteBot
 from pywikibot.exceptions import InvalidPageError, NoPageError
 from pywikibot.tools import chars
@@ -979,9 +979,9 @@
     # The summary stored here won't be actually used but is only an example
     site = pywikibot.Site()
     single_summary = None
-
-    for old, new in pairwise(commandline_replacements):
-        replacement = Replacement(old, new)
+    for i in range(0, len(commandline_replacements), 2):
+        replacement = Replacement(commandline_replacements[i],
+                                  commandline_replacements[i + 1])
         if not single_summary:
             single_summary = i18n.twtranslate(
                 site, 'replace-replacing',
diff --git a/scripts/template.py b/scripts/template.py
index 58421bd..7e83f71 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -113,7 +113,6 @@

 import pywikibot
 from pywikibot import i18n, pagegenerators, textlib
-from pywikibot.backports import pairwise
 from pywikibot.bot import SingleSiteBot
 from pywikibot.pagegenerators import XMLDumpPageGenerator
 from pywikibot.tools.itertools import filter_unique, roundrobin_generators
@@ -216,6 +215,7 @@
     :param args: command line arguments
     """
     template_names = []
+    templates = {}
     options = {}
     # If xmlfilename is None, references will be loaded from the live wiki.
     xmlfilename = None
@@ -266,16 +266,17 @@
         return

     if bool(options.get('subst', False)) ^ options.get('remove', False):
-        templates = {name: None for name in template_names}
+        for template_name in template_names:
+            templates[template_name] = None
     else:
-        if len(template_names) % 2:
-            pywikibot.warning('Unless using solely -subst or -remove, you'
-                              'must give an even number of template names.')
+        try:
+            for i in range(0, len(template_names), 2):
+                templates[template_names[i]] = template_names[i + 1]
+        except IndexError:
+            pywikibot.output('Unless using solely -subst or -remove, '
+                             'you must give an even number of template names.')
             return

-        templates = {key: value
-                     for key, value in pairwise(template_names)}
-
     old_templates = [pywikibot.Page(site, template_name, ns=10)
                      for template_name in templates]


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

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

Reply via email to