jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[typing] Add some type hints

Change-Id: Idd5004b3cd589696b77b6a3b4635ab0e434315e4
---
M pywikibot/data/api.py
M pywikibot/family.py
M pywikibot/scripts/generate_user_files.py
M pywikibot/userinterfaces/gui.py
M pywikibot/userinterfaces/terminal_interface_base.py
M pywikibot/userinterfaces/win32_unicode.py
M pywikibot/version.py
M scripts/interwiki.py
M scripts/protect.py
M scripts/replace.py
M scripts/revertbot.py
M scripts/solve_disambiguation.py
12 files changed, 29 insertions(+), 63 deletions(-)

diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 7c81237..90e8198 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -1258,7 +1258,7 @@

self.__defaulted = True

- def _encoded_items(self):
+ def _encoded_items(self) -> Dict[str, Union[str, bytes]]:
"""
Build a dict of params with minimal encoding needed for the site.

@@ -1272,7 +1272,6 @@
are not supported.

:return: Parameters either in the site encoding, or ASCII strings
- :rtype: dict with values of either str or bytes
"""
params = {}
for key, values in self._params.items():
@@ -1978,12 +1977,8 @@
request_key = repr(sorted(self._encoded_items().items()))
return '{!r}{}{}'.format(self.site, user_key, request_key)

- def _create_file_name(self):
- """
- Return a unique ascii identifier for the cache entry.
-
- :rtype: str (hexadecimal; i.e. characters 0-9 and a-f only)
- """
+ def _create_file_name(self) -> str:
+ """Return a unique ascii identifier for the cache entry."""
return hashlib.sha256(
self._uniquedescriptionstr().encode('utf-8')
).hexdigest()
diff --git a/pywikibot/family.py b/pywikibot/family.py
index b49f88d..171e740 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -19,7 +19,7 @@

import pywikibot
from pywikibot import config
-from pywikibot.backports import Dict, List, Tuple
+from pywikibot.backports import Dict, List, Set, Tuple
from pywikibot.exceptions import FamilyMaintenanceWarning, UnknownFamilyError
from pywikibot.tools import classproperty, deprecated

@@ -803,12 +803,8 @@
"""Return the path to title using index.php with redirects disabled."""
return '{}?title={}&redirect=no'.format(self.path(code), title)

- def interface(self, code):
- """
- Return interface to use for code.
-
- :rtype: str or subclass of BaseSite
- """
+ def interface(self, code) -> str:
+ """Return interface to use for code."""
if code in self.interwiki_removals:
if code in self.codes:
pywikibot.warn('Interwiki removal {} is in {} codes'
@@ -953,14 +949,13 @@
return putText

@property
- def obsolete(self):
+ def obsolete(self) -> Dict[str, Optional[str]]:
"""
Old codes that are not part of the family.

Interwiki replacements override removals for the same code.

:return: mapping of old codes to new codes (or None)
- :rtype: dict
"""
data = {code: None for code in self.interwiki_removals}
data.update(self.interwiki_replacements)
@@ -977,13 +972,11 @@
if new is not None)

@classproperty
- def domains(cls):
+ def domains(cls) -> Set[str]:
"""
Get list of unique domain names included in this family.

These domains may also exist in another family.
-
- :rtype: set of str
"""
return set(cls.langs.values())

@@ -1234,14 +1227,13 @@
return '{}.wikimedia.org'.format(cls.name)


-def AutoFamily(name: str, url: str):
+def AutoFamily(name: str, url: str) -> SingleSiteFamily:
"""
Family that automatically loads the site configuration.

:param name: Name for the family
:param url: API endpoint URL of the wiki
:return: Generated family class
- :rtype: SingleSiteFamily
"""
url = urlparse.urlparse(url)
domain = url.netloc
diff --git a/pywikibot/scripts/generate_user_files.py b/pywikibot/scripts/generate_user_files.py
index 7924328..0281985 100755
--- a/pywikibot/scripts/generate_user_files.py
+++ b/pywikibot/scripts/generate_user_files.py
@@ -5,7 +5,7 @@
moved to pywikibot.scripts folder
"""
#
-# (C) Pywikibot team, 2010-2021
+# (C) Pywikibot team, 2010-2022
#
# Distributed under the terms of the MIT license.
#
@@ -18,6 +18,7 @@
from textwrap import fill
from typing import Optional

+from pywikibot.backports import Tuple
from pywikibot.scripts import _import_with_no_user_config


@@ -105,7 +106,7 @@
default_lang: Optional[str] = 'en',
default_username: Optional[str] = None,
force: bool = False
-):
+) -> Tuple[str, str, str]:
"""
Ask the user for the family, site code and username.

@@ -114,7 +115,6 @@
if the family supports it.
:param default_username: The default username which should be chosen.
:return: The family, site code and username
- :rtype: tuple of three str
"""
known_families = sorted(pywikibot.config.family_files.keys())
if default_family not in known_families:
@@ -251,11 +251,10 @@
return data


-def copy_sections():
+def copy_sections() -> str:
"""Take config sections and copy them to user-config.py.

:return: config text of all selected sections.
- :rtype: str
"""
result = []
sections = parse_sections()
@@ -382,7 +381,7 @@
raise


-def ask_for_dir_change(force):
+def ask_for_dir_change(force) -> Tuple[bool, bool]:
"""Ask whether the base directory is has to be changed.

Only give option for directory change if user-config.py or user-password
@@ -392,7 +391,6 @@
:param force: Skip asking for directory change
:type force: bool
:return: whether user file or password file exists already
- :rtype: tuple of bool
"""
global base_dir

diff --git a/pywikibot/userinterfaces/gui.py b/pywikibot/userinterfaces/gui.py
index c13e761..b75ba4a 100644
--- a/pywikibot/userinterfaces/gui.py
+++ b/pywikibot/userinterfaces/gui.py
@@ -7,7 +7,7 @@
Python 3.6 or highter is required.
"""
#
-# (C) Pywikibot team, 2003-2021
+# (C) Pywikibot team, 2003-2022
#
# Distributed under the terms of the MIT license.
#
@@ -373,7 +373,7 @@
self.pack()

def edit(self, text: str, jumpIndex: Optional[int] = None,
- highlight: Optional[str] = None):
+ highlight: Optional[str] = None) -> Optional[str]:
"""
Provide user with editor to modify text.

@@ -382,7 +382,6 @@
:param highlight: each occurrence of this substring will be highlighted
:return: the modified text, or None if the user didn't save the text
file in his text editor
- :rtype: str or None
"""
self.text = None
# put given text into our textarea
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index 9aa998a..7417155 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -488,7 +488,7 @@
pywikibot.error('Invalid response')

def editText(self, text: str, jumpIndex: Optional[int] = None,
- highlight: Optional[str] = None):
+ highlight: Optional[str] = None) -> Optional[str]:
"""Return the text as edited by the user.

Uses a Tkinter edit box because we don't have a console editor
@@ -498,7 +498,6 @@
:param highlight: each occurrence of this substring will be highlighted
:return: the modified text, or None if the user didn't save the text
file in his text editor
- :rtype: str or None
"""
try:
from pywikibot.userinterfaces import gui
diff --git a/pywikibot/userinterfaces/win32_unicode.py b/pywikibot/userinterfaces/win32_unicode.py
index 4c67edf..ae7c1f5 100755
--- a/pywikibot/userinterfaces/win32_unicode.py
+++ b/pywikibot/userinterfaces/win32_unicode.py
@@ -231,7 +231,6 @@
Get Unicode console objects.

:return: stdin, stdout, stderr, argv
- :rtype: tuple
"""
# Make Unicode console output work independently of the current code page.
# This also fixes https://bugs.python.org/issue1602
diff --git a/pywikibot/version.py b/pywikibot/version.py
index fa621fb..5032ebe 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -1,6 +1,6 @@
"""Module to determine the pywikibot version (tag, revision and date)."""
#
-# (C) Pywikibot team, 2007-2021
+# (C) Pywikibot team, 2007-2022
#
# Distributed under the terms of the MIT license.
#
@@ -22,7 +22,7 @@

import pywikibot
from pywikibot import config
-from pywikibot.backports import List, cache
+from pywikibot.backports import cache, Dict, List, Tuple
from pywikibot.comms.http import fetch
from pywikibot.exceptions import VersionParseError

@@ -78,7 +78,7 @@


@cache
-def getversiondict():
+def getversiondict() -> Dict[str, str]:
"""Get version info for the package.

:return:
@@ -86,7 +86,6 @@
- rev (current revision identifier),
- date (date of current revision),
- hash (git hash for the current revision)
- :rtype: ``dict`` of four ``str``
"""
_program_dir = _get_program_dir()
exceptions = {}
@@ -305,7 +304,7 @@
return (tag, rev, date, hsh)


-def getversion_package(path=None):
+def getversion_package(path=None) -> Tuple[str, str, str, str]:
"""Get version info for an installed package.

:param path: Unused argument
@@ -314,7 +313,6 @@
- rev: '-1 (unknown)'
- date (date the package was installed locally),
- hash (git hash for the current revision of 'pywikibot/__init__.py')
- :rtype: ``tuple`` of four ``str``
"""
hsh = ''
date = get_module_mtime(pywikibot).timetuple()
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 89e8958..30b5ef0 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -2163,7 +2163,7 @@
return True


-def page_empty_check(page):
+def page_empty_check(page) -> bool:
"""
Return True if page should be skipped as it is almost empty.

@@ -2171,8 +2171,6 @@
50 characters, and other pages are considered empty if they are not
category pages and contain less than 4 characters excluding interlanguage
links and categories.
-
- :rtype: bool
"""
txt = page.text
# Check if the page is in content namespace
diff --git a/scripts/protect.py b/scripts/protect.py
index a01947a..985442d 100755
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -57,7 +57,7 @@
#
# Created by modifying delete.py
#
-# (C) Pywikibot team, 2008-2021
+# (C) Pywikibot team, 2008-2022
#
# Distributed under the terms of the MIT license.
#
@@ -115,11 +115,10 @@
protections=protections)


-def check_protection_level(operation, level, levels, default=None):
+def check_protection_level(operation, level, levels, default=None) -> str:
"""Check if the protection level is valid or ask if necessary.

:return: a valid protection level
- :rtype: str
"""
if level in levels:
return level
diff --git a/scripts/replace.py b/scripts/replace.py
index f19690f..7e4b2da 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -459,11 +459,7 @@
.format(entry.title))

def isTitleExcepted(self, title) -> bool:
- """
- Return True if one of the exceptions applies for the given title.
-
- :rtype: bool
- """
+ """Return True if one of the exceptions applies for the given title."""
if 'title' in self.exceptions:
for exc in self.exceptions['title']:
if exc.search(title):
@@ -475,12 +471,8 @@

return False

- def isTextExcepted(self, text):
- """
- Return True if one of the exceptions applies for the given text.
-
- :rtype: bool
- """
+ def isTextExcepted(self, text) -> bool:
+ """Return True if one of the exceptions applies for the given text."""
if 'text-contains' in self.exceptions:
return any(exc.search(text)
for exc in self.exceptions['text-contains'])
diff --git a/scripts/revertbot.py b/scripts/revertbot.py
index a5435fa..0273267 100755
--- a/scripts/revertbot.py
+++ b/scripts/revertbot.py
@@ -20,12 +20,11 @@

'''Example revert bot.'''

- def callback(self, item):
+ def callback(self, item) -> bool:
'''Sample callback function for 'private' revert bot.

:param item: an item from user contributions
:type item: dict
- :rtype: bool
'''
if 'top' in item:
page = pywikibot.Page(self.site, item['title'])
@@ -36,7 +35,7 @@

"""
#
-# (C) Pywikibot team, 2008-2021
+# (C) Pywikibot team, 2008-2022
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index 41286ca..63e3e2e 100755
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -452,8 +452,6 @@
"""Initializer.

:type disamb_page: pywikibot.Page
- :rtype: None
-
"""
self.disamb_page = disamb_page
self.enabled = enabled

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Idd5004b3cd589696b77b6a3b4635ab0e434315e4
Gerrit-Change-Number: 769476
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged