jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/611834 )
Change subject: Update noreferences for py3 ......................................................................
Update noreferences for py3
Bug: T257399 Change-Id: If3fb28bd9cd2c54d35d9ffeea5089571c243af70 --- M scripts/noreferences.py 1 file changed, 10 insertions(+), 16 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/noreferences.py b/scripts/noreferences.py index 390eb03..9e5a160 100755 --- a/scripts/noreferences.py +++ b/scripts/noreferences.py @@ -34,18 +34,14 @@ # # Distributed under the terms of the MIT license. # -from __future__ import absolute_import, division, unicode_literals - import re
from functools import partial
import pywikibot
-from pywikibot import i18n, pagegenerators, textlib, Bot -from pywikibot.pagegenerators import ( - XMLDumpPageGenerator, -) +from pywikibot import Bot, i18n, pagegenerators, textlib +from pywikibot.pagegenerators import XMLDumpPageGenerator
# This is required for the text that is shown when you run this script # with the parameter -help. @@ -484,7 +480,7 @@ _references_regex = re.compile('<references.*?/>', re.IGNORECASE)
-def _match_xml_page_text(text): +def _match_xml_page_text(text) -> bool: """Match page text.""" text = textlib.removeDisabledParts(text) return _ref_regex.search(text) and not _references_regex.search(text) @@ -498,12 +494,12 @@
"""References section bot."""
- def __init__(self, generator, **kwargs): + def __init__(self, generator, **kwargs) -> None: """Initializer.""" self.availableOptions.update({ 'verbose': True, }) - super(NoReferencesBot, self).__init__(**kwargs) + super().__init__(**kwargs)
self.generator = pagegenerators.PreloadingGenerator(generator) self.site = pywikibot.Site() @@ -523,7 +519,7 @@ except KeyError: self.referencesText = '<references />'
- def lacksReferences(self, text): + def lacksReferences(self, text) -> bool: """Check whether or not the page is lacking a references tag.""" oldTextCleaned = textlib.removeDisabledParts(text) if self.referencesR.search(oldTextCleaned) or \ @@ -549,7 +545,7 @@ pywikibot.output('Found ref without references.') return True
- def addReferences(self, oldText): + def addReferences(self, oldText) -> str: """ Add a references tag into an existing section where it fits into.
@@ -560,7 +556,6 @@ @param oldText: page text to be modified @type oldText: str @return: The modified pagetext - @rtype: str """ # Do we have a malformed <reference> tag which could be repaired? # Set the edit summary for this case @@ -670,7 +665,7 @@ index = len(tmpText) return self.createReferenceSection(oldText, index)
- def createReferenceSection(self, oldText, index, ident='=='): + def createReferenceSection(self, oldText, index, ident='==') -> str: """Create a reference section and insert it into the given text.
@param oldText: page text that is going to be be amended @@ -682,7 +677,6 @@ title @type ident: str @return: the amended page text with reference section added - @rtype: str """ if self.site.code in noTitleRequired: ref_section = '\n\n%s\n' % self.referencesText @@ -692,7 +686,7 @@ ident=ident, text=self.referencesText) return oldText[:index].rstrip() + ref_section + oldText[index:]
- def run(self): + def run(self) -> None: """Run the bot.""" for page in self.generator: self.current_page = page @@ -736,7 +730,7 @@ .format(page.title(as_link=True)))
-def main(*args): +def main(*args) -> None: """ Process command line arguments and invoke bot.