Skip to content

Commit 0dbc6b8

Browse files
committed
Add equality testing methods to most objects
Closes sigmavirus24#69
1 parent a0b2c1d commit 0dbc6b8

21 files changed

Lines changed: 158 additions & 12 deletions

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ include AUTHORS.rst
55
include run_tests.py
66
prune *.pyc
77
recursive-include github3/*
8+
recursive-include docs/*
9+
prune docs/_build/

github3/auths.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def __init__(self, auth, session=None):
4141
def __repr__(self):
4242
return '<Authorization [{0}]>'.format(self.name)
4343

44+
def __eq__(self, other):
45+
return self.id == other.id
46+
47+
def __ne__(self, other):
48+
return self.id != other.id
49+
4450
def _update_(self, auth):
4551
self.__init__(auth, self._session)
4652

github3/events.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ def __init__(self, event):
4444
def __repr__(self):
4545
return '<Event [{0}]>'.format(self.type[:-5])
4646

47+
def __eq__(self, other):
48+
return self.id == other.id
49+
50+
def __ne__(self, other):
51+
return self.id != other.id
52+
4753
@staticmethod
4854
def list_types():
4955
"""List available payload types"""

github3/gists/gist.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ def __init__(self, data, session=None):
6969
#: History of this gist, list of :class:`GistHistory <GistHistory>`
7070
self.history = [GistHistory(h, self) for h in data.get('history', [])]
7171

72-
def __eq__(self, gist):
73-
return self.id == gist.id
72+
def __eq__(self, other):
73+
return self.id == other.id
74+
75+
def __ne__(self, other):
76+
return self.id != other.id
7477

7578
def __str__(self):
7679
return self.id

github3/gists/history.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ def __init__(self, history, session=None):
3434
def __repr__(self):
3535
return '<Gist History [{0}]>'.format(self.version)
3636

37+
def __eq__(self, other):
38+
return self.version == other.version
39+
40+
def __ne__(self, other):
41+
return self.version != other.version
42+
3743
def get_gist(self):
3844
"""Retrieves the gist at this version.
3945

github3/issues/event.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ def __init__(self, event, issue=None):
3333
#: Dictionary of links for the pull request
3434
self.pull_request = event.get('pull_request', {})
3535

36+
def __eq__(self, other):
37+
return self.commit_id == other.commit_id
38+
39+
def __ne__(self, other):
40+
return self.commit_id != other.commit_id
41+
3642
def __repr__(self):
3743
return '<Issue Event [#{0} - {1}]>'.format(
3844
self.issue.number, self.event

github3/issues/issue.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ def __init__(self, issue, session=None):
6666
#: :class:`User <github3.users.User>` who opened the issue.
6767
self.user = User(issue.get('user'), self._session)
6868

69-
def __eq__(self, issue):
70-
return self.id == issue.id
69+
def __eq__(self, other):
70+
return self.id == other.id
71+
72+
def __ne__(self, other):
73+
return self.id != other.id
7174

7275
def __repr__(self):
7376
return '<Issue [{r[0]}/{r[1]} #{n}]>'.format(r=self.repository,

github3/models.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ def __init__(self, comment, session):
241241
self.html_url = self.links.get('html')
242242
self.pull_request_url = self.links.get('pull_request')
243243

244+
def __eq__(self, other):
245+
return self.id == other.id
246+
247+
def __ne__(self, other):
248+
return self.id != other.id
249+
244250
def _update_(self, comment):
245251
self.__init__(comment, self._session)
246252

@@ -286,6 +292,12 @@ def __init__(self, commit, session):
286292
i = self._api.rfind('/')
287293
self.sha = self._api[i + 1:]
288294

295+
def __eq__(self, other):
296+
return self.sha == other.sha
297+
298+
def __ne__(self, other):
299+
return self.sha != other.sha
300+
289301

290302
class BaseAccount(GitHubCore):
291303
"""The :class:`BaseAccount <BaseAccount>` object. This is used to do the
@@ -346,8 +358,11 @@ def __init__(self, acct, session):
346358
#: Markdown formatted biography
347359
self.bio = acct.get('bio')
348360

349-
def __eq__(self, acc):
350-
return self.id == acc.id
361+
def __eq__(self, other):
362+
return self.id == other.id
363+
364+
def __ne__(self, other):
365+
return self.id != other.id
351366

352367
def __repr__(self):
353368
return '<{s.type} [{s.login}:{s.name}]>'.format(s=self)

github3/orgs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def __init__(self, team, session=None):
3232
def __repr__(self):
3333
return '<Team [{0}]>'.format(self.name)
3434

35+
def __eq__(self, other):
36+
return self.id == other.id
37+
38+
def __ne__(self, other):
39+
return self.id != other.id
40+
3541
def _update_(self, team):
3642
self.__init__(team, self._session)
3743

github3/pulls.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ def __init__(self, pull, session=None):
164164
def __repr__(self):
165165
return '<Pull Request [#{0}]>'.format(self.number)
166166

167+
def __eq__(self, other):
168+
return self.id == other.id
169+
170+
def __ne__(self, other):
171+
return self.id != other.id
172+
167173
def _update_(self, pull):
168174
self.__init__(pull, self._session)
169175

0 commit comments

Comments
 (0)