jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/611676 )
Change subject: Update coordinate_import for py3 ......................................................................
Update coordinate_import for py3
Bug: T257399 Change-Id: I4361127f3410dc7542404d204be2dbad32276e4b --- M scripts/coordinate_import.py 1 file changed, 9 insertions(+), 14 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py index 39868cd..b37e987 100755 --- a/scripts/coordinate_import.py +++ b/scripts/coordinate_import.py @@ -37,11 +37,11 @@ ¶ms; """ # -# (C) Pywikibot team, 2013-2019 +# (C) Pywikibot team, 2013-2020 # # Distributed under the terms of MIT License. # -from __future__ import absolute_import, division, unicode_literals +from typing import Optional
import pywikibot from pywikibot import pagegenerators, WikidataBot @@ -56,20 +56,20 @@
use_from_page = None
- def __init__(self, generator, **kwargs): + def __init__(self, generator, **kwargs) -> None: """ Initializer.
@param generator: A generator that yields Page objects. """ self.availableOptions['create'] = False - super(CoordImportRobot, self).__init__(**kwargs) + super().__init__(**kwargs) self.generator = generator self.cacheSources() self.prop = 'P625' self.create_missing_item = self.getOption('create')
- def has_coord_qualifier(self, claims): + def has_coord_qualifier(self, claims) -> Optional[str]: """ Check if self.prop is used as property for a qualifier.
@@ -77,7 +77,6 @@ @type claims: dict @return: the first property for which self.prop is used as qualifier, or None if any - @return: unicode or None """ for prop in claims: for claim in claims[prop]: @@ -85,12 +84,11 @@ return prop return None
- def item_has_coordinates(self, item): + def item_has_coordinates(self, item) -> bool: """ Check if the item has coordinates.
@return: whether the item has coordinates - @rtype: bool """ claims = item.get().get('claims') if self.prop in claims: @@ -106,7 +104,7 @@ return True return False
- def treat_page_and_item(self, page, item): + def treat_page_and_item(self, page, item) -> None: """Treat page/item.""" if self.item_has_coordinates(item): return @@ -120,13 +118,12 @@
self.try_import_coordinates_from_page(page, item)
- def try_import_coordinates_from_page(self, page, item): + def try_import_coordinates_from_page(self, page, item) -> bool: """ Try import coordinate from the given page to the given item.
@return: whether any coordinates were found and the import was successful - @rtype: bool """ coordinate = page.coordinates(primary_only=True) if not coordinate: @@ -149,7 +146,7 @@ return True
-def main(*args): +def main(*args) -> None: """ Process command line arguments and invoke bot.
@@ -176,10 +173,8 @@ if generator: coordbot = CoordImportRobot(generator, create=create_new) coordbot.run() - return True else: pywikibot.bot.suggest_help(missing_generator=True) - return False
if __name__ == '__main__':