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

Change subject: [IMPR] Avoid deeply nested flow statement in category.py
......................................................................

[IMPR] Avoid deeply nested flow statement in category.py

Change-Id: If2740960043a985fa8338c250bfba1d31aa46d63
---
M scripts/category.py
1 file changed, 28 insertions(+), 23 deletions(-)

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



diff --git a/scripts/category.py b/scripts/category.py
index 418a4ff..a0f86dd 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -1,5 +1,4 @@
 #!/usr/bin/python
-# -*- coding: utf-8 -*-
 """
 Script to manage categories.

@@ -113,7 +112,7 @@
 This will move all pages in the category US to the category United States.
 """
 #
-# (C) Pywikibot team, 2004-2020
+# (C) Pywikibot team, 2004-2021
 #
 # Distributed under the terms of the MIT license.
 #
@@ -247,32 +246,38 @@
         @type page: pywikibot.Page
         @return: Page to be categorized.
         """
+        if page.namespace() != page.site.namespaces.TEMPLATE:
+            self.includeonly = []
+            return page
+
+        try:
+            tmpl, loc = moved_links[page.site.code]
+        except KeyError:
+            tmpl = []
+
+        if not isinstance(tmpl, list):
+            tmpl = [tmpl]
+
         includeonly = []
-        if page.namespace() == page.site.namespaces.TEMPLATE:
-            try:
-                tmpl, loc = moved_links[page.site.code]
-            except KeyError:
-                tmpl = []
-            if not isinstance(tmpl, list):
-                tmpl = [tmpl]
-            if tmpl != []:
-                templates = page.templatesWithParams()
-                for template, params in templates:
-                    if (template.title(with_ns=False).lower() in tmpl
-                            and params):
-                        doc_page = pywikibot.Page(page.site, params[0])
-                        if doc_page.exists():
-                            page = doc_page
-                            includeonly = ['includeonly']
-                            break
-            if includeonly == []:
-                docs = page.site.doc_subpage  # return tuple
-                for doc in docs:
-                    doc_page = pywikibot.Page(page.site, page.title() + doc)
+        if tmpl:
+            templates = page.templatesWithParams()
+            for template, params in templates:
+                if template.title(with_ns=False).lower() in tmpl and params:
+                    doc_page = pywikibot.Page(page.site, params[0])
                     if doc_page.exists():
                         page = doc_page
                         includeonly = ['includeonly']
                         break
+
+        if not includeonly:
+            docs = page.site.doc_subpage  # return tuple
+            for doc in docs:
+                doc_page = pywikibot.Page(page.site, page.title() + doc)
+                if doc_page.exists():
+                    page = doc_page
+                    includeonly = ['includeonly']
+                    break
+
         self.includeonly = includeonly
         return page


--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/654888
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: If2740960043a985fa8338c250bfba1d31aa46d63
Gerrit-Change-Number: 654888
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: Ricordisamoa <[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