Skip to content

Commit

Permalink
Concentrated hash and eq inside TrelloBase to avoid repetition
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Christian committed Apr 23, 2017
1 parent 46e468c commit 60af41b
Show file tree
Hide file tree
Showing 9 changed files with 429 additions and 463 deletions.
14 changes: 4 additions & 10 deletions trello/attachments.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
from dateutil import parser as dateparser

from trello import TrelloBase

class Attachments(object):

class Attachments(TrelloBase):
"""
https://developers.trello.com/advanced-reference/card#get-1-cards-card-id-or-shortlink-attachments
"""
def __init__(self, id, bytes, date, edge_color, idMember, is_upload, mime_type, name, previews, url):
super().__init__()
self.id = id
self.bytes = bytes
self.date = dateparser.parse(date)
Expand Down Expand Up @@ -36,15 +39,6 @@ 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
15 changes: 15 additions & 0 deletions trello/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-


class TrelloBase(object):
def __init__(self):
self.id = None

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
Loading

0 comments on commit 60af41b

Please sign in to comment.