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

Change subject: interwiki: Reuse namespace values
......................................................................

interwiki: Reuse namespace values

Resolve the origin and linked namespaces once when checking a mismatch.
Reuse them for namespace mappings, messages, and the user prompt.

Change-Id: Ie734fc59d616b212c35d927596390d20f4155447
---
M scripts/interwiki.py
1 file changed, 15 insertions(+), 11 deletions(-)

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




diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index aa8f172..61f2b2a 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -874,22 +874,27 @@
             # We have seen this page before, don't ask again.
             return False

-        if self.origin and self.origin.namespace() != linkedPage.namespace():
+        origin = self.origin
+        if not origin:
+            return False
+
+        origin_ns = origin.namespace()
+        linked_ns = linkedPage.namespace()
+        if origin_ns != linked_ns:
             # Allow for a mapping between different namespaces
-            crossFrom = self.origin.site.family.crossnamespace.get(
-                self.origin.namespace(), {})
-            crossTo = crossFrom.get(self.origin.site.code,
+            crossFrom = origin.site.family.crossnamespace.get(origin_ns, {})
+            crossTo = crossFrom.get(origin.site.code,
                                     crossFrom.get('_default', {}))
             nsmatch = crossTo.get(linkedPage.site.code,
                                   crossTo.get('_default', []))
-            if linkedPage.namespace() in nsmatch:
+            if linked_ns in nsmatch:
                 return False

             if self.conf.autonomous:
                 pywikibot.info(
                     f'NOTE: Ignoring link from page {linkingPage} in namespace'
                     f' {linkingPage.namespace()} to page {linkedPage} in '
-                    f'namespace {linkedPage.namespace()}.'
+                    f'namespace {linked_ns}.'
                 )
                 # Fill up found_in, so that we will not write this notice
                 self.found_in[linkedPage] = [linkingPage]
@@ -900,16 +905,16 @@
                 pywikibot.info(
                     f'NOTE: Ignoring link from page {linkingPage} in '
                     f'namespace {linkingPage.namespace()} to page '
-                    f'{linkedPage} in namespace {linkedPage.namespace()} '
+                    f'{linkedPage} in namespace {linked_ns} '
                     f'because page {preferredPage} in the correct namespace'
                     ' has already been found.'
                 )
                 return True

             choice = pywikibot.input_choice(
-                f'WARNING: {self.origin} is in namespace '
-                f'"{self.origin.namespace()}", but {linkedPage} is in '
-                f'namespace "{linkedPage.namespace()}". Follow it anyway?',
+                f'WARNING: {origin} is in namespace "{origin_ns}", but '
+                f'{linkedPage} is in namespace "{linked_ns}". Follow it '
+                'anyway?',
                 [('Yes', 'y'), ('No', 'n'), ('Add an alternative', 'a'),
                  ('give up', 'g')],
                 automatic_quit=False)
@@ -930,7 +935,6 @@
                 return True

         # same namespaces, no problem
-        # or no origin page yet, also no problem
         return False

     def disambigMismatch(self, page, counter):

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