jenkins-bot submitted this change.

View Change


Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
[IMPR] Ensure that _cmpkey method is defined in subclasses of ComparableMixin

Change-Id: I91921c8f4548de62b834e223865f23a05ce63117
---
M pywikibot/tools/__init__.py
1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 1c06290..023b922 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -1,9 +1,10 @@
"""Miscellaneous helper functions (not wiki-dependent)."""
#
-# (C) Pywikibot team, 2008-2022
+# (C) Pywikibot team, 2008-2023
#
# Distributed under the terms of the MIT license.
#
+import abc
import bz2
import gzip
import hashlib
@@ -226,13 +227,22 @@


# From http://python3porting.com/preparing.html
-class ComparableMixin:
+class ComparableMixin(abc.ABC):

"""Mixin class to allow comparing to other objects which are comparable.

.. versionadded:: 3.0
"""

+ @abc.abstractmethod
+ def _cmpkey(self) -> Any:
+ """Abstract method to return key for comparison of objects.
+
+ This ensures that ``_cmpkey`` method is defined in subclass.
+
+ .. versionadded:: 8.2
+ """
+
def __lt__(self, other):
"""Compare if self is less than other."""
return other > self._cmpkey()

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I91921c8f4548de62b834e223865f23a05ce63117
Gerrit-Change-Number: 910813
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged