jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/378987 )
Change subject: Implement Claim.__eq__ ......................................................................
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(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
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): """
pywikibot-commits@lists.wikimedia.org