jenkins-bot submitted this change.

View Change

Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
[IMPR] Avoid deeply nested control flow statements in _pages submodule

Change-Id: Id6bf247eb3364986d225ebaef11a209f2f94317d
---
M pywikibot/page/_pages.py
1 file changed, 36 insertions(+), 21 deletions(-)

diff --git a/pywikibot/page/_pages.py b/pywikibot/page/_pages.py
index 2c8838e..11a89fb 100644
--- a/pywikibot/page/_pages.py
+++ b/pywikibot/page/_pages.py
@@ -2198,6 +2198,7 @@
intkeys[int(key)] = args[key]
except ValueError:
named[key] = args[key]
+
for i in range(1, len(intkeys) + 1):
# only those args with consecutive integer keys can be
# treated as positional; an integer could also be used
@@ -2205,11 +2206,13 @@
# example: {{tmp|one|two|5=five|three}}
if i in intkeys:
positional.append(intkeys[i])
- else:
- for k in intkeys:
- if k < 1 or k >= i:
- named[str(k)] = intkeys[k]
- break
+ continue
+
+ for k in intkeys:
+ if k < 1 or k >= i:
+ named[str(k)] = intkeys[k]
+ break
+
for item in named.items():
positional.append('{}={}'.format(*item))
result.append((pywikibot.Page(link, self.site), positional))
@@ -2374,6 +2377,7 @@
"""
if not isinstance(recurse, bool) and recurse:
recurse = recurse - 1
+
if not hasattr(self, '_subcats'):
self._subcats = []
for member in self.site.categorymembers(
@@ -2385,14 +2389,17 @@
total -= 1
if total == 0:
return
+
if recurse:
for item in subcat.subcategories(
recurse, total=total, content=content):
yield item
- if total is not None:
- total -= 1
- if total == 0:
- return
+ if total is None:
+ continue
+
+ total -= 1
+ if total == 0:
+ return
else:
for subcat in self._subcats:
yield subcat
@@ -2400,14 +2407,17 @@
total -= 1
if total == 0:
return
+
if recurse:
for item in subcat.subcategories(
recurse, total=total, content=content):
yield item
- if total is not None:
- total -= 1
- if total == 0:
- return
+ if total is None:
+ continue
+
+ total -= 1
+ if total == 0:
+ return

def articles(self,
recurse: Union[int, bool] = False,
@@ -2489,12 +2499,15 @@
hash_value = hash(article)
if hash_value in seen:
continue
+
seen.add(hash_value)
yield article
- if total is not None:
- total -= 1
- if total == 0:
- return
+ if total is None:
+ continue
+
+ total -= 1
+ if total == 0:
+ return

def members(self, recurse: bool = False,
namespaces=None,
@@ -2518,10 +2531,12 @@
for article in subcat.members(
recurse, namespaces, total=total, content=content):
yield article
- if total is not None:
- total -= 1
- if total == 0:
- return
+ if total is None:
+ continue
+
+ total -= 1
+ if total == 0:
+ return

def isEmptyCategory(self) -> bool:
"""Return True if category has no members (including subcategories)."""

To view, visit change 813593. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Id6bf247eb3364986d225ebaef11a209f2f94317d
Gerrit-Change-Number: 813593
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged