jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/750721 )
Change subject: [types] Add type hints ......................................................................
[types] Add type hints
https://deepsource.io/gh/xqt/pwb/issues?category=typecheck&analyzer=all&...
Change-Id: I627c186c1db767651fbba4535378bfcd97c8b437 --- M pywikibot/backports.py M pywikibot/scripts/generate_user_files.py M scripts/welcome.py 3 files changed, 9 insertions(+), 11 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/backports.py b/pywikibot/backports.py index 1660b53..ee524c2 100644 --- a/pywikibot/backports.py +++ b/pywikibot/backports.py @@ -63,6 +63,7 @@ from typing import ( Dict, FrozenSet, + Generator, Iterable, Iterator, List, @@ -75,7 +76,9 @@ Type, ) else: - from collections.abc import Iterable, Iterator, Mapping, Sequence + from collections.abc import ( + Generator, Iterable, Iterator, Mapping, Sequence, + ) from re import Match, Pattern Dict = dict # type: ignore[misc] FrozenSet = frozenset # type: ignore[misc] diff --git a/pywikibot/scripts/generate_user_files.py b/pywikibot/scripts/generate_user_files.py index 1a364c2..f5d3752 100755 --- a/pywikibot/scripts/generate_user_files.py +++ b/pywikibot/scripts/generate_user_files.py @@ -22,10 +22,6 @@ from pywikibot.scripts import _import_with_no_user_config
PYTHON_VERSION = sys.version_info[:2] -if PYTHON_VERSION >= (3, 9): - Tuple = tuple -else: - from typing import Tuple
# DISABLED_SECTIONS cannot be copied; variables must be set manually @@ -410,7 +406,7 @@ return userfile, passfile
-def main(*args: Tuple[str, ...]): +def main(*args: str): """ Process command line arguments and generate user-config.
diff --git a/scripts/welcome.py b/scripts/welcome.py index 518cd19..e79bdc1 100755 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -170,11 +170,10 @@ from enum import Enum from random import choice from textwrap import fill -from typing import Generator
import pywikibot from pywikibot import config, i18n -from pywikibot.backports import List +from pywikibot.backports import Dict, Generator, List from pywikibot.bot import SingleSiteBot from pywikibot.exceptions import EditConflictError, Error, HiddenKeyError from pywikibot.tools.formatter import color_format @@ -468,9 +467,9 @@ """Initializer.""" super().__init__(**kwargs) self.check_managed_sites() - self.bname = {} + self.bname = {} # type: Dict[str, str]
- self.welcomed_users = [] + self.welcomed_users = [] # type: List[str] self.log_name = i18n.translate(self.site, logbook)
if not self.log_name: @@ -740,7 +739,7 @@ "{} doesn't allow random signature, force disable." .format(self.site)) globalvar.randomSign = False - return None + return []
sign_page = pywikibot.Page(self.site, sign_page_name) if sign_page.exists():