jenkins-bot has submitted this change and it was merged. Change subject: Comparable to delegate to other ......................................................................
Comparable to delegate to other The Comparable mixin currently depends on `other` also being Comparable. It did not check that they were of the same class. It should let `other` decide how comparison should be done with the value of self._cmpkey(). This is slightly less efficient, but allows comparision with any object which is comparable with self._cmpkey(), which includes other objects of the same class as they should both have the same object type in self._cmpkey(). Change-Id: Id33df6c848479bc3b589a0e282a6a05ca84c22ba --- M pywikibot/tools.py 1 file changed, 7 insertions(+), 15 deletions(-) Approvals: John Vandenberg: Looks good to me, but someone else must approve XZise: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/tools.py b/pywikibot/tools.py index 9254200..b90cc5e 100644 --- a/pywikibot/tools.py +++ b/pywikibot/tools.py @@ -52,33 +52,25 @@ # From http://python3porting.com/preparing.html class ComparableMixin(object): - """Mixin class to allow comparing to other objects of this class.""" - - def _compare(self, other, method): - try: - return method(self._cmpkey(), other._cmpkey()) - except (AttributeError, TypeError): - # _cmpkey not implemented, or return different type, - # so I can't compare with "other". - return NotImplemented + """Mixin class to allow comparing to other objects which are comparable.""" def __lt__(self, other): - return self._compare(other, lambda s, o: s < o) + return other >= self._cmpkey() def __le__(self, other): - return self._compare(other, lambda s, o: s <= o) + return other > self._cmpkey() def __eq__(self, other): - return self._compare(other, lambda s, o: s == o) + return other == self._cmpkey() def __ge__(self, other): - return self._compare(other, lambda s, o: s >= o) + return other < self._cmpkey() def __gt__(self, other): - return self._compare(other, lambda s, o: s > o) + return other <= self._cmpkey() def __ne__(self, other): - return self._compare(other, lambda s, o: s != o) + return other != self._cmpkey() class MediaWikiVersion(Version): -- To view, visit https://gerrit.wikimedia.org/r/170724 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Id33df6c848479bc3b589a0e282a6a05ca84c22ba Gerrit-PatchSet: 2 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: John Vandenberg <[email protected]> Gerrit-Reviewer: John Vandenberg <[email protected]> Gerrit-Reviewer: Ladsgroup <[email protected]> Gerrit-Reviewer: Merlijn van Deen <[email protected]> Gerrit-Reviewer: XZise <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ Pywikibot-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
