jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/508023 )
Change subject: [cleanup] check for existing strings directly ......................................................................
[cleanup] check for existing strings directly
- don't use "!=" operator if checking for an empty string - don't use "elsif" or "else" if condition has a return statemant previously
Change-Id: Iaae83bbc3e98d84c0e2c55e9d9da0222b6919a7e --- M scripts/commonscat.py 1 file changed, 13 insertions(+), 11 deletions(-)
Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/commonscat.py b/scripts/commonscat.py index 9f59c0a..473db6a 100755 --- a/scripts/commonscat.py +++ b/scripts/commonscat.py @@ -279,34 +279,36 @@ currentCommonscatTarget, LinkText, Note) = commonscatLink checkedCommonscatTarget = self.checkCommonscatLink( currentCommonscatTarget) + if (currentCommonscatTarget == checkedCommonscatTarget): # The current commonscat link is good pywikibot.output('Commonscat link at {} to Category:{} is ok' .format(page.title(), currentCommonscatTarget)) return True - elif checkedCommonscatTarget != '': + + if checkedCommonscatTarget: # We have a new Commonscat link, replace the old one self.changeCommonscat(page, currentCommonscatTemplate, currentCommonscatTarget, primaryCommonscat, checkedCommonscatTarget, LinkText, Note) return True - else: - # Commonscat link is wrong - commonscatLink = self.findCommonscatLink(page) - if (commonscatLink != ''): - self.changeCommonscat(page, currentCommonscatTemplate, - currentCommonscatTarget, - primaryCommonscat, commonscatLink) - # TODO: if the commonsLink == '', should it be removed? + + # Commonscat link is wrong + commonscatLink = self.findCommonscatLink(page) + if commonscatLink: + self.changeCommonscat(page, currentCommonscatTemplate, + currentCommonscatTarget, + primaryCommonscat, commonscatLink) + # TODO: if the commonsLink == '', should it be removed?
elif self.skipPage(page): pywikibot.output('Found a template in the skip list. Skipping ' + page.title()) else: commonscatLink = self.findCommonscatLink(page) - if (commonscatLink != ''): + if commonscatLink: if commonscatLink == page.title(): textToAdd = '{{%s}}' % primaryCommonscat else: @@ -379,7 +381,7 @@ possibleCommonscat, linkText, Note) = commonscatLink checkedCommonscat = self.checkCommonscatLink( possibleCommonscat) - if (checkedCommonscat != ''): + if checkedCommonscat: pywikibot.output( 'Found link for {} at [[{}:{}]] to {}.' .format(page.title(), ipage.site.code, ipage.title(),
pywikibot-commits@lists.wikimedia.org