jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/558583 )
Change subject: [IMPR] Avoid deeply nested flow statements
......................................................................
[IMPR] Avoid deeply nested flow statements
- for loop is able to handle empty iterators
- use a tuple with endswith to reduce one for loop
Change-Id: I47c39266b26f6492faa8cc4a9c66a785808224a9
---
M scripts/imagerecat.py
1 file changed, 8 insertions(+), 8 deletions(-)
Approvals:
D3r1ck01: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/imagerecat.py b/scripts/imagerecat.py
index d4db6aa..adeba2a 100755
--- a/scripts/imagerecat.py
+++ b/scripts/imagerecat.py
@@ -148,14 +148,14 @@
for country in countries:
if country in cat:
listCountries.append(country)
- if len(listByCountry) > 0:
- for bc in listByCountry:
- category = pywikibot.Category(
- pywikibot.Site('commons', 'commons'), 'Category:'
+ bc)
- for subcategory in category.subcategories():
- for country in listCountries:
- if subcategory.title(with_ns=False).endswith(country):
- result.append(subcategory.title(with_ns=False))
+
+ country_tuple = tuple(listCountries)
+ for bc in listByCountry:
+ category = pywikibot.Category(
+ pywikibot.Site('commons', 'commons'), 'Category:' +
bc)
+ for subcategory in category.subcategories():
+ if subcategory.title(with_ns=False).endswith(country_tuple):
+ result.append(subcategory.title(with_ns=False))
return list(set(result))
--
To view, visit
https://gerrit.wikimedia.org/r/558583
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I47c39266b26f6492faa8cc4a9c66a785808224a9
Gerrit-Change-Number: 558583
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: jenkins-bot (75)