jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/348209 )
Change subject: [IMPR] Unify edit summary arguments ......................................................................
[IMPR] Unify edit summary arguments
- rename edit summary argument from 'comment' to 'summary' for _cosmetic_changes_hook and change_category methods - Now _cosmetic_changes_hook always returns the edit summary either modified or unchanged. This is due to PEP8: "Either all return statements in a function should return an expression, or none of them should." - add doc string for _cosmetic_changes_hook method
Change-Id: I0ba98b74a2cc52af902cbe274fd7a7e8bd81626c --- M pywikibot/page.py 1 file changed, 20 insertions(+), 12 deletions(-)
Approvals: Dalba: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 60b7b7a..6295b21 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -1260,7 +1260,7 @@ """Helper function for save().""" link = self.title(asLink=True) if cc or cc is None and config.cosmetic_changes: - summary = self._cosmetic_changes_hook(summary) or summary + summary = self._cosmetic_changes_hook(summary)
done = self.site.editpage(self, summary=summary, minor=minor, watch=watch, bot=botflag, **kwargs) @@ -1271,10 +1271,18 @@ if not quiet: pywikibot.output('Page %s saved' % link)
- def _cosmetic_changes_hook(self, comment): + def _cosmetic_changes_hook(self, summary): + """The cosmetic changes hook. + + @param summary: The current edit summary. + @type summary: str + @return: Modified edit summary if cosmetic changes has been done, + else the old edit summary. + @rtype: str + """ if self.isTalkPage() or \ pywikibot.calledModuleName() in config.cosmetic_changes_deny_script: - return + return summary family = self.site.family.name if config.cosmetic_changes_mylang_only: cc = ((family == config.family and @@ -1287,7 +1295,7 @@ (family in list(config.cosmetic_changes_disable.keys()) and self.site.lang in config.cosmetic_changes_disable[family])) if not cc: - return + return summary
old = self.text pywikibot.log(u'Cosmetic changes for %s-%s enabled.' @@ -1300,12 +1308,11 @@ pageTitle=self.title(), ignore=CANCEL_MATCH) self.text = ccToolkit.change(old) - if comment and \ - old.strip().replace('\r\n', - '\n') != self.text.strip().replace('\r\n', '\n'): + if summary and old.strip().replace( + '\r\n', '\n') != self.text.strip().replace('\r\n', '\n'): from pywikibot import i18n - comment += i18n.twtranslate(self.site, 'cosmetic_changes-append') - return comment + summary += i18n.twtranslate(self.site, 'cosmetic_changes-append') + return summary
@deprecate_arg('async', 'asynchronous') # T106230 @deprecated_args(comment='summary') @@ -2042,7 +2049,8 @@ if answer == 'y': return self.site.protect(self, protections, reason, **kwargs)
- def change_category(self, oldCat, newCat, comment=None, sortKey=None, + @deprecated_args(comment='summary') + def change_category(self, oldCat, newCat, summary=None, sortKey=None, inPlace=True, include=[]): """ Remove page from oldCat and add it to newCat. @@ -2052,7 +2060,7 @@ @param newCat: category to be added, if any @type newCat: Category or None
- @param comment: string to use as an edit summary + @param summary: string to use as an edit summary
@param sortKey: sortKey to use for the added category. Unused if newCat is None, or if inPlace=True @@ -2116,7 +2124,7 @@
if oldtext != newtext: try: - self.put(newtext, comment) + self.put(newtext, summary) return True except pywikibot.PageSaveRelatedError as error: pywikibot.output(u'Page %s not saved: %s'