jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/971570 )
Change subject: [IMPR] solve mypy issues in tools.collections ......................................................................
[IMPR] solve mypy issues in tools.collections
- add type annotations for SizedKeyCollection.data - initialize the data dict in __init__ and clear the dict in clear method - make GeneratorWrapper.generator an abstract generator instead of an iterator
Change-Id: I80e0b351ea4a08b68ee0c812c08e555dd570da26 --- M pywikibot/tools/collections.py 1 file changed, 20 insertions(+), 4 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/tools/collections.py b/pywikibot/tools/collections.py index e351e55..b3e2bdf 100644 --- a/pywikibot/tools/collections.py +++ b/pywikibot/tools/collections.py @@ -1,6 +1,6 @@ """Collections datatypes.""" # -# (C) Pywikibot team, 2014-2022 +# (C) Pywikibot team, 2014-2023 # # Distributed under the terms of the MIT license. # @@ -11,6 +11,7 @@ from itertools import chain from typing import Any
+from pywikibot.backports import Dict, List from pywikibot.backports import Generator as GeneratorType
@@ -68,7 +69,8 @@ with this collection which will be used as key. """ self.keyattr = keyattr - self.clear() + self.data: Dict[Any, List[Any]] = {} + self.size = 0
def __contains__(self, key) -> bool: return key in self.data @@ -120,7 +122,7 @@
def clear(self) -> None: """Remove all elements from SizedKeyCollection.""" - self.data = {} # defaultdict fails (T282865) + self.data.clear() # defaultdict fails (T282865) self.size = 0
def filter(self, key): @@ -250,7 +252,7 @@ @abstractmethod def generator(self) -> GeneratorType[Any, Any, Any]: """Abstract generator property.""" - return iter(()) + yield from ()
def send(self, value: Any) -> Any: """Return next yielded value from generator or raise StopIteration.
pywikibot-commits@lists.wikimedia.org