Skip to content

Commit

Permalink
Implement hash for CompletableGithubObject (#1922)
Browse files Browse the repository at this point in the history
Since CompletableGithubObject already uses its URL attribute to
implement equality, extend it to also use that attribute for hashing.

Fixes #1826
  • Loading branch information
s-t-e-v-e-n-k committed Apr 26, 2021
1 parent e416810 commit 4faff23
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 3 additions & 0 deletions github/GithubObject.py
Expand Up @@ -286,6 +286,9 @@ def __init__(self, requester, headers, attributes, completed):
def __eq__(self, other):
return other.__class__ is self.__class__ and other._url.value == self._url.value

def __hash__(self):
return hash(self._url.value)

def __ne__(self, other):
return not self == other

Expand Down
6 changes: 2 additions & 4 deletions tests/Equality.py
Expand Up @@ -30,16 +30,14 @@ class Equality(Framework.TestCase):
def testUserEquality(self):
u1 = self.g.get_user("jacquev6")
u2 = self.g.get_user("jacquev6")
self.assertTrue(u1 == u2)
self.assertFalse(u1 != u2)
self.assertEqual(u1, u2)
self.assertEqual(hash(u1), hash(u2))

def testUserDifference(self):
u1 = self.g.get_user("jacquev6")
u2 = self.g.get_user("OddBloke")
self.assertFalse(u1 == u2)
self.assertTrue(u1 != u2)
self.assertNotEqual(u1, u2)
self.assertNotEqual(hash(u1), hash(u2))

def testBranchEquality(self):
# Erf, equality of NonCompletableGithubObjects will be difficult to implement
Expand Down

0 comments on commit 4faff23

Please sign in to comment.