Skip to content

Commit

Permalink
- Added __hash__ and __eq__ for some more modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Christian committed Apr 22, 2017
1 parent 799bbe8 commit 46e468c
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 7 deletions.
9 changes: 9 additions & 0 deletions trello/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ def from_json(json_obj):
def __repr__(self):
return u"<Attachments {0}>".format(self.name)

def __hash__(self):
class_name = type(self).__name__
return hash(class_name) ^ hash(self.id)

def __eq__(self, other):
if isinstance(other, type(self)):
return hash(self) == hash(other)
raise NotImplementedError


class AttachmentsPreview(object):
def __init__(self, bytes, url, width, height, is_scaled):
Expand Down
9 changes: 9 additions & 0 deletions trello/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ def from_json(cls, trello_client=None, organization=None, json_obj=None):
def __repr__(self):
return force_str(u'<Board %s>' % self.name)

def __hash__(self):
class_name = type(self).__name__
return hash(class_name) ^ hash(self.id)

def __eq__(self, other):
if isinstance(other, type(self)):
return hash(self) == hash(other)
raise NotImplementedError

def fetch(self):
"""Fetch all attributes for this board"""
json_obj = self.client.fetch_json('/boards/' + self.id)
Expand Down
9 changes: 9 additions & 0 deletions trello/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ def from_json(cls, parent, json_obj):
def __repr__(self):
return force_str(u'<Card %s>' % self.name)

def __hash__(self):
class_name = type(self).__name__
return hash(class_name) ^ hash(self.id)

def __eq__(self, other):
if isinstance(other, type(self)):
return hash(self) == hash(other)
raise NotImplementedError

def fetch(self, eager=True):
"""
Fetch all attributes for this card
Expand Down
9 changes: 9 additions & 0 deletions trello/checklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,12 @@ def _get_item_index(self, name):

def __repr__(self):
return force_str(u'<Checklist %s>' % self.id)

def __hash__(self):
class_name = type(self).__name__
return hash(class_name) ^ hash(self.id)

def __eq__(self, other):
if isinstance(other, type(self)):
return hash(self) == hash(other)
raise NotImplementedError
14 changes: 7 additions & 7 deletions trello/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ def from_json_list(cls, board, json_objs):
def __repr__(self):
return force_str(u'<Label %s>' % self.name)

def fetch(self):
"""Fetch all attributes for this label"""
json_obj = self.client.fetch_json('/labels/' + self.id)
self.name = json_obj['name']
self.color = json_obj['color']
return self

def __hash__(self):
class_name = type(self).__name__
return hash(class_name) ^ hash(self.id)
Expand All @@ -49,3 +42,10 @@ def __eq__(self, other):
if isinstance(other, type(self)):
return hash(self) == hash(other)
raise NotImplementedError

def fetch(self):
"""Fetch all attributes for this label"""
json_obj = self.client.fetch_json('/labels/' + self.id)
self.name = json_obj['name']
self.color = json_obj['color']
return self
9 changes: 9 additions & 0 deletions trello/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def __init__(self, client, member_id, full_name=''):
def __repr__(self):
return force_str(u'<Member %s>' % self.id)

def __hash__(self):
class_name = type(self).__name__
return hash(class_name) ^ hash(self.id)

def __eq__(self, other):
if isinstance(other, type(self)):
return hash(self) == hash(other)
raise NotImplementedError

def fetch(self):
"""Fetch all attributes for this member"""
json_obj = self.client.fetch_json(
Expand Down
9 changes: 9 additions & 0 deletions trello/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ def from_json(cls, trello_client, json_obj):
def __repr__(self):
return force_str(u'<Organization %s>' % self.name)

def __hash__(self):
class_name = type(self).__name__
return hash(class_name) ^ hash(self.id)

def __eq__(self, other):
if isinstance(other, type(self)):
return hash(self) == hash(other)
raise NotImplementedError

def fetch(self):
"""Fetch all attributes for this organization"""
json_obj = self.client.fetch_json('/organizations/' + self.id)
Expand Down
9 changes: 9 additions & 0 deletions trello/trellolist.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def from_json(cls, board, json_obj):
def __repr__(self):
return force_str(u'<List %s>' % self.name)

def __hash__(self):
class_name = type(self).__name__
return hash(class_name) ^ hash(self.id)

def __eq__(self, other):
if isinstance(other, type(self)):
return hash(self) == hash(other)
raise NotImplementedError

def fetch(self):
"""Fetch all attributes for this list"""
json_obj = self.client.fetch_json('/lists/' + self.id)
Expand Down

0 comments on commit 46e468c

Please sign in to comment.