jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] Rewrite pywikibot scripts to support Python 3.5+ only

Bug: T257399
Change-Id: I78754dd9fd6f45c6ff89cdddf0fab97cd422f193
---
M scripts/add_text.py
M scripts/template.py
M scripts/unlink.py
M scripts/watchlist.py
M tests/add_text_tests.py
M tests/cache_tests.py
M tests/fixing_redirects_tests.py
7 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/scripts/add_text.py b/scripts/add_text.py
index e832e62..54c2289 100755
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -170,13 +170,13 @@
@param always: Always add text without user confirmation
@param up: If True, add text to top of page, else add at bottom.
@param putText: If True, save changes to the page, else return
- (text, newtext, always)
+ (_, newtext, _)
@param oldTextGiven: If None fetch page text, else use this text
@param reorderEnabled: If True place text above categories and
interwiki, else place at page bottom. No effect if up = False.
@param create: Create page if it does not exist
@return: If putText=True: (success, success, always)
- else: (text, newtext, always)
+ else: (_, newtext, _)
"""
site = page.site
if not summary:
@@ -339,10 +339,10 @@
if talkPage:
generator = pagegenerators.PageWithTalkPageGenerator(generator, True)
for page in generator:
- (text, newtext, always) = add_text(page, addText, summary, regexSkip,
- regexSkipUrl, always, up, True,
- reorderEnabled=reorderEnabled,
- create=talkPage)
+ (_, newtext, _) = add_text(page, addText, summary, regexSkip,
+ regexSkipUrl, always, up, True,
+ reorderEnabled=reorderEnabled,
+ create=talkPage)


if __name__ == '__main__':
diff --git a/scripts/template.py b/scripts/template.py
index adfd01b..8ba187f 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -133,7 +133,7 @@
(cur table), and may not still transclude the template.
"""

- def __init__(self, templates, xmlfilename) -> None:
+ def __init__(self, templates, xmlfilename: str) -> None:
"""
Initializer.

@@ -141,7 +141,6 @@
templates
@type templateNames: list
@param xmlfilename: The dump's path, either absolute or relative
- @type xmlfilename: str

"""
self.templates = templates
@@ -171,7 +170,7 @@

"""This bot will replace, remove or subst all occurrences of a template."""

- def __init__(self, generator, templates, **kwargs) -> None:
+ def __init__(self, generator, templates: dict, **kwargs) -> None:
"""
Initializer.

@@ -180,7 +179,6 @@
@param templates: a dictionary which maps old template names to
their replacements. If remove or subst is True, it maps the
names of the templates that should be removed/resolved to None.
- @type templates: dict
"""
self.available_options.update({
'addcat': None,
diff --git a/scripts/unlink.py b/scripts/unlink.py
index 46598ce..6887534 100755
--- a/scripts/unlink.py
+++ b/scripts/unlink.py
@@ -23,11 +23,10 @@
python pwb.py unlink "Foo bar" -namespace:0 -namespace:6
"""
#
-# (C) Pywikibot team, 2007-2019
+# (C) Pywikibot team, 2007-2020
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals

import pywikibot
from pywikibot.bot import SingleSiteBot
@@ -42,7 +41,7 @@

def __init__(self, pageToUnlink, **kwargs):
"""Initialize a UnlinkBot instance with the given page to unlink."""
- super(UnlinkBot, self).__init__(**kwargs)
+ super().__init__(**kwargs)
self.pageToUnlink = pageToUnlink
self.generator = pageToUnlink.getReferences(
namespaces=self.opt.namespaces, content=True)
diff --git a/scripts/watchlist.py b/scripts/watchlist.py
index 72122b2..a7b083c 100755
--- a/scripts/watchlist.py
+++ b/scripts/watchlist.py
@@ -25,8 +25,6 @@
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import os

import pywikibot
@@ -79,7 +77,7 @@
def refresh_all():
"""Reload watchlists for all wikis where a watchlist is already present."""
cache_path = CachedRequest._get_cache_dir()
- files = os.listdir(cache_path)
+ files = os.scandir(cache_path)
seen = set()
for filename in files:
entry = CacheEntry(cache_path, filename)
diff --git a/tests/add_text_tests.py b/tests/add_text_tests.py
index df6223e..fb55f41 100644
--- a/tests/add_text_tests.py
+++ b/tests/add_text_tests.py
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-
"""Test add_text bot module."""
#
-# (C) Pywikibot team, 2016-2018
+# (C) Pywikibot team, 2016-2020
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import pywikibot

from scripts.add_text import add_text, get_text
@@ -25,12 +23,12 @@

def setUp(self):
"""Setup test."""
- super(TestAdding, self).setUp()
+ super().setUp()
self.page = pywikibot.Page(self.site, 'foo')

def test_basic(self):
"""Test adding text."""
- (text, newtext, always) = add_text(
+ (_, newtext, _) = add_text(
self.page, 'bar', putText=False,
oldTextGiven='foo\n{{linkfa}}')
self.assertEqual(
@@ -39,7 +37,7 @@

def test_with_category(self):
"""Test adding text before categories."""
- (text, newtext, always) = add_text(
+ (_, newtext, _) = add_text(
self.page, 'bar', putText=False,
oldTextGiven='foo\n[[Category:Foo]]')
self.assertEqual(
diff --git a/tests/cache_tests.py b/tests/cache_tests.py
index b2c8cae..06e82c6 100644
--- a/tests/cache_tests.py
+++ b/tests/cache_tests.py
@@ -5,8 +5,6 @@
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
from pywikibot.site import BaseSite

import scripts.maintenance.cache as cache
diff --git a/tests/fixing_redirects_tests.py b/tests/fixing_redirects_tests.py
index 10239ba..32f5e0d 100644
--- a/tests/fixing_redirects_tests.py
+++ b/tests/fixing_redirects_tests.py
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-
"""Test fixing redirects bot module."""
#
-# (C) Pywikibot team, 2018
+# (C) Pywikibot team, 2018-2020
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import pywikibot

from scripts.fixing_redirects import FixingRedirectBot

To view, visit change 640360. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I78754dd9fd6f45c6ff89cdddf0fab97cd422f193
Gerrit-Change-Number: 640360
Gerrit-PatchSet: 3
Gerrit-Owner: Udoka <UdokakuUgochukwu@gmail.com>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged