jenkins-bot submitted this change.
Update templatecount to py3
Bug: T257399
Change-Id: I635e1fabca5006dfbf5b7fb409c9c20d8db8fec8
---
M scripts/templatecount.py
1 file changed, 12 insertions(+), 19 deletions(-)
diff --git a/scripts/templatecount.py b/scripts/templatecount.py
index 8bb513c..8e9930e 100755
--- a/scripts/templatecount.py
+++ b/scripts/templatecount.py
@@ -38,21 +38,19 @@
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import datetime
+from typing import Dict, Generator, List, Tuple
+
import pywikibot
-templates = ['ref', 'note', 'ref label', 'note label', 'reflist']
-
-class TemplateCountRobot(object):
+class TemplateCountRobot:
"""Template count bot."""
@classmethod
- def countTemplates(cls, templates, namespaces):
+ def countTemplates(cls, templates, namespaces) -> None:
"""
Display number of transclusions for a list of templates.
@@ -78,7 +76,7 @@
.format(datetime.datetime.utcnow().isoformat()))
@classmethod
- def listTemplates(cls, templates, namespaces):
+ def listTemplates(cls, templates, namespaces) -> None:
"""
Display transcluded pages for a list of templates.
@@ -105,7 +103,8 @@
.format(datetime.datetime.utcnow().isoformat()))
@classmethod
- def template_dict(cls, templates, namespaces):
+ def template_dict(cls, templates, namespaces) -> Dict[
+ str, List[pywikibot.Page]]:
"""
Create a dict of templates and its transcluded pages.
@@ -116,13 +115,12 @@
@type templates: list
@param namespaces: list of namespace numbers
@type namespaces: list
-
- @rtype: dict
"""
return dict(cls.template_dict_generator(templates, namespaces))
@staticmethod
- def template_dict_generator(templates, namespaces):
+ def template_dict_generator(templates, namespaces) -> Generator[
+ Tuple[str, List[pywikibot.Page]], None, None]:
"""
Yield transclusions of each template in 'templates'.
@@ -134,21 +132,16 @@
@type templates: list
@param namespaces: list of namespace numbers
@type namespaces: list
-
- @rtype: generator
"""
mysite = pywikibot.Site()
mytpl = mysite.namespaces.TEMPLATE
for template in templates:
- transcluding_array = []
gen = pywikibot.Page(mysite, template, ns=mytpl).getReferences(
namespaces=namespaces, only_template_inclusion=True)
- for page in gen:
- transcluding_array.append(page)
- yield template, transcluding_array
+ yield template, list(gen)
-def main(*args):
+def main(*args) -> None:
"""
Process command line arguments and invoke bot.
@@ -178,7 +171,7 @@
robot = TemplateCountRobot()
if not args_list:
- args_list = templates
+ args_list = ['ref', 'note', 'ref label', 'note label', 'reflist']
if 'reflist' in args_list:
pywikibot.output(
To view, visit change 611938. To unsubscribe, or for help writing mail filters, visit settings.