jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] Type hint corrections

I made two mistakes when I began adding type hints...

1. Some type hinting predated our mypy configuration file.

2. I incorrectly ran '--follow-imports skip' whereas JJMC89 uses 'silent',
which made us receive different warnings.

This makes our mypy checks pass to the best extent I can (bot_choices.py
still has warnings due to T286844).

Change-Id: Ib8ce68bef471492b9da6be7d2f2af5c496f9aefd
---
M mypy.ini
M pywikibot/backports.py
M pywikibot/bot_choice.py
M pywikibot/cosmetic_changes.py
4 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/mypy.ini b/mypy.ini
index 4eb6afc..228fda5 100644
--- a/mypy.ini
+++ b/mypy.ini
@@ -3,6 +3,7 @@
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
+ignore_missing_imports = true
no_implicit_optional = true
show_error_codes = true
warn_redundant_casts = true
diff --git a/pywikibot/backports.py b/pywikibot/backports.py
index b565a48..00f880a 100644
--- a/pywikibot/backports.py
+++ b/pywikibot/backports.py
@@ -11,7 +11,7 @@

# functools.cache
if PYTHON_VERSION >= (3, 9):
- from functools import cache
+ from functools import cache # type: ignore[attr-defined]
else:
from functools import lru_cache as _lru_cache
cache = _lru_cache(None)
@@ -30,26 +30,28 @@
def __enter__(self) -> Any:
return self.result

- def __exit__(self, *args) -> None:
+ def __exit__(self, *args: Any) -> None:
pass
else:
- from contextlib import nullcontext
+ from contextlib import nullcontext # type: ignore[misc]


# queue
if PYTHON_VERSION < (3, 7):
from queue import Queue as SimpleQueue
else:
- from queue import SimpleQueue
+ from queue import SimpleQueue # type: ignore[misc]


# typing
if PYTHON_VERSION < (3, 5, 2):
from typing import Dict as DefaultDict
elif PYTHON_VERSION < (3, 9):
- from typing import DefaultDict
+ from typing import DefaultDict # type: ignore[misc]
else:
- from collections import defaultdict as DefaultDict # noqa: N812
+ from collections import ( # type: ignore[misc] # noqa: N812
+ defaultdict as DefaultDict
+ )


if PYTHON_VERSION < (3, 7, 2):
@@ -59,7 +61,6 @@
else:
from collections import OrderedDict

-
if PYTHON_VERSION < (3, 9):
from typing import (
Callable,
@@ -77,17 +78,17 @@
else:
from collections.abc import Callable, Iterable, Mapping, Sequence
from re import Match, Pattern
- Dict = dict
- FrozenSet = frozenset
- List = list
- Set = set
- Tuple = tuple
+ Dict = dict # type: ignore[misc]
+ FrozenSet = frozenset # type: ignore[misc]
+ List = list # type: ignore[misc]
+ Set = set # type: ignore[misc]
+ Tuple = tuple # type: ignore[assignment]


# PEP 616 string methods
if PYTHON_VERSION >= (3, 9):
- removeprefix = str.removeprefix
- removesuffix = str.removesuffix
+ removeprefix = str.removeprefix # type: ignore[attr-defined]
+ removesuffix = str.removesuffix # type: ignore[attr-defined]
else:
def removeprefix(string: str, prefix: str) -> str:
"""Remove prefix from a string or return a copy otherwise.
diff --git a/pywikibot/bot_choice.py b/pywikibot/bot_choice.py
index 7f35e7a..0107862 100755
--- a/pywikibot/bot_choice.py
+++ b/pywikibot/bot_choice.py
@@ -153,7 +153,7 @@

"""An option with a description and shortcut and returning the shortcut."""

- def __init__(self, option: str, shortcut: str, **kwargs) -> None:
+ def __init__(self, option: str, shortcut: str, **kwargs: Any) -> None:
"""
Initializer.

@@ -191,7 +191,7 @@
"""An option which calls out property of the given output class."""

def __init__(self, option: str, shortcut: str, output: OutputOption,
- **kwargs) -> None:
+ **kwargs: Any) -> None:
"""Create a new option for the given sequence."""
super().__init__(option, shortcut, **kwargs)
self._outputter = output
@@ -390,7 +390,7 @@
"""An option allowing a range of integers."""

def __init__(self, minimum: int = 1, maximum: Optional[int] = None,
- prefix: str = '', **kwargs) -> None:
+ prefix: str = '', **kwargs: Any) -> None:
"""Initializer."""
super().__init__(**kwargs)
if not ((minimum is None or isinstance(minimum, int))
@@ -468,7 +468,8 @@

"""An option to select something from a list."""

- def __init__(self, sequence: Sequence[str], prefix='', **kwargs) -> None:
+ def __init__(self, sequence: Sequence[str], prefix='',
+ **kwargs: Any) -> None:
"""Initializer."""
self._list = sequence
try:
@@ -505,7 +506,7 @@

def __init__(self, sequence: Sequence[str], prefix: str = '',
pre: Optional[str] = None, post: Optional[str] = None,
- **kwargs) -> None:
+ **kwargs: Any) -> None:
"""Initializer.

:param pre: Additional comment printed before the list.
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 9fb3780..96ac707 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -382,8 +382,10 @@
2. additional information depending on the local site policy
3. interwiki
"""
+ assert self.title is not None
+
categories = []
- interwiki_links = []
+ interwiki_links = {}

# get categories
if not self.template:

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib8ce68bef471492b9da6be7d2f2af5c496f9aefd
Gerrit-Change-Number: 708603
Gerrit-PatchSet: 1
Gerrit-Owner: Damian <atagar1@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged