Explorar o código

objects: Make ShaFile.__eq__ work when other is not a ShaFile.

Change-Id: I3944e84ae64ea1ddb6acbc51b171b6a039cccf04
Dave Borowitz %!s(int64=13) %!d(string=hai) anos
pai
achega
0f867aa906
Modificáronse 2 ficheiros con 7 adicións e 5 borrados
  1. 2 0
      NEWS
  2. 5 5
      dulwich/objects.py

+ 2 - 0
NEWS

@@ -28,6 +28,8 @@
 
   * Support ~ in git:// URL paths. (Jelmer Vernooij, #813555)
 
+  * Make ShaFile.__eq__ work when other is not a ShaFile. (Dave Borowitz)
+
  API CHANGES
 
   * write_pack no longer takes the num_objects argument and requires an object

+ 5 - 5
dulwich/objects.py

@@ -469,15 +469,15 @@ class ShaFile(object):
         return "<%s %s>" % (self.__class__.__name__, self.id)
 
     def __ne__(self, other):
-        return self.id != other.id
+        return not isinstance(other, ShaFile) or self.id != other.id
 
     def __eq__(self, other):
-        """Return true if the sha of the two objects match.
+        """Return True if the SHAs of the two objects match.
 
-        The __le__ etc methods aren't overriden as they make no sense,
-        certainly at this level.
+        It doesn't make sense to talk about an order on ShaFiles, so we don't
+        override the rich comparison methods (__le__, etc.).
         """
-        return self.id == other.id
+        return isinstance(other, ShaFile) and self.id == other.id
 
 
 class Blob(ShaFile):