Proposed patch fixes several bugs in plistlib.Data.__eq__(). * isinstance(other, str) was used instead of isinstance(other, bytes). Data always wraps bytes and should be comparable with bytes. str was correct type in Python 2. * id(self) == id(other) is always false, because if other is self, the first condition (isinstance(other, self.__class__)) should be true. NotImplemented should be returned as fallback. This allows comparing with Data subclasses and correct work of __ne__(). * The __eq__() method should be used instead of the equality operator. This is needed for correct work in case if value is bytes subclass with overloaded __eq__().
>>> import plistlib >>> class MyData(bytes): ... def __eq__(self, other): ... if isinstance(other, plistlib.Data): ... return super().__eq__(other.value) ... return False ... >>> plistlib.Data(b'x') == MyData(b'x') True If use the equality operator the result is False. I don't know if this is good example. In any case this is corner case and we can manage with "==".
Serhiy, I slightly prefer the second patch, but either one would be fine. The reason I asked about explicitly calling __eq__ is that this is an uncommon pattern (at least for me). Ronald