jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
Implement Claim.__eq__

Claims are same when they are derived from the same
property, have the same target and qualifiers
(which are also claims, so this comparison happens
recursively).

Bug: T76615
Change-Id: Ib082ebf8c5a11f1e79e3d863d4f8d4b1fe2ef8da
---
M pywikibot/page.py
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 1fbd1c2..c89d5e4 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -26,6 +26,7 @@
import unicodedata

from collections import Counter, defaultdict, namedtuple, OrderedDict
+from itertools import chain
from warnings import warn

import pywikibot
@@ -4871,6 +4872,21 @@
return '{cls_name}.fromJSON({0}, {1})'.format(
repr(self.repo), self.toJSON(), cls_name=type(self).__name__)

+ def __eq__(self, other):
+ if not isinstance(other, self.__class__):
+ return False
+
+ for attr in ('id', 'snaktype', 'target'):
+ if getattr(self, attr) != getattr(other, attr):
+ return False
+
+ my_qualifiers = set(chain.from_iterable(self.qualifiers.values()))
+ other_qualifiers = set(chain.from_iterable(other.qualifiers.values()))
+ return my_qualifiers == other_qualifiers
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
@classmethod
def fromJSON(cls, site, data):
"""

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib082ebf8c5a11f1e79e3d863d4f8d4b1fe2ef8da
Gerrit-Change-Number: 378987
Gerrit-PatchSet: 3
Gerrit-Owner: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Lokal Profil <andre.costa@wikimedia.se>
Gerrit-Reviewer: Magul <tomasz.magulski@gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)