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

Change subject: [IMPR] Avoid deeply nested flow statements in redirect.py
......................................................................

[IMPR] Avoid deeply nested flow statements in redirect.py

Change-Id: I9b1cc85262630c59b5f1726bac839be65878352e
---
M scripts/redirect.py
1 file changed, 24 insertions(+), 30 deletions(-)

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



diff --git a/scripts/redirect.py b/scripts/redirect.py
index 9b07caf..80fa4de 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -1,5 +1,4 @@
 #!/usr/bin/python
-# -*- coding: utf-8 -*-
 """
 Script to resolve double redirects, and to delete broken redirects.

@@ -70,7 +69,7 @@

 """
 #
-# (C) Pywikibot team, 2004-2020
+# (C) Pywikibot team, 2004-2021
 #
 # Distributed under the terms of the MIT license.
 #
@@ -256,24 +255,21 @@
                          for x in data['query']['redirects']}

             for pagetitle in data['query']['pages'].values():
-                if 'missing' in pagetitle and 'pageid' not in pagetitle:
-                    pages[pagetitle['title']] = False
-                else:
-                    pages[pagetitle['title']] = True
+                pages[pagetitle['title']] = \
+                    'missing' not in pagetitle or 'pageid' in pagetitle
             for redirect in redirects:
                 target = redirects[redirect]
-                result = 0
+                result = None
                 final = None
-                try:
-                    if pages[target]:
-                        final = target
-                        with suppress(KeyError):
-                            while result <= maxlen:
-                                result += 1
-                                final = redirects[final]
-                            # result = None
-                except KeyError:
-                    result = None
+
+                if pages.get(target):
+                    result = 0
+                    final = target
+                    with suppress(KeyError):
+                        while result <= maxlen:
+                            result += 1
+                            final = redirects[final]
+
                 yield (redirect, result, target, final)

     def retrieve_broken_redirects(self) -> Generator[
@@ -281,14 +277,13 @@
         """Retrieve broken redirects."""
         if self.opt.fullscan:
             count = 0
-            for (pagetitle, type, target, final) \
-                    in self.get_redirects_via_api(maxlen=2):
+            for pagetitle, type, target, final in self.get_redirects_via_api(
+                    maxlen=2):
                 if type == 0:
                     yield pagetitle
-                    if self.opt.limit:
-                        count += 1
-                        if count >= self.opt.limit:
-                            break
+                    count += 1
+                    if self.opt.limit and count >= self.opt.limit:
+                        break
         elif self.opt.xml:
             # retrieve information from XML dump
             pywikibot.output(
@@ -311,14 +306,13 @@
             yield from self.get_moved_pages_redirects()
         elif self.opt.fullscan:
             count = 0
-            for (pagetitle, type, target, final) \
-                    in self.get_redirects_via_api(maxlen=2):
-                if type != 0 and type != 1:
+            for pagetitle, type_, target, final in self.get_redirects_via_api(
+                    maxlen=2):
+                if type_ != 0 and type_ != 1:
                     yield pagetitle
-                    if self.opt.limit:
-                        count += 1
-                        if count >= self.opt.limit:
-                            break
+                    count += 1
+                    if self.opt.limit and count >= self.opt.limit:
+                        break
         elif self.opt.xml:
             redict, _ = self.get_redirects_from_dump()
             total = len(redict)

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/654869
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: I9b1cc85262630c59b5f1726bac839be65878352e
Gerrit-Change-Number: 654869
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to