From: mohammed chamma Date: Tue, 24 Dec 2019 03:18:01 +0000 (-0500) Subject: make User object hashable to allow use with sets X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=cd93b6d2d96b57501f97a4e2fbbea92ae4f9f865;p=tweepy.git make User object hashable to allow use with sets this allows for one-liners like ```connections = list(set(followers) & set(friends))``` --- diff --git a/tweepy/models.py b/tweepy/models.py index 7c33d8f..aceb398 100644 --- a/tweepy/models.py +++ b/tweepy/models.py @@ -224,7 +224,12 @@ class User(Model): return result return not result - + + def __hash__(self): + if hasattr(self, 'id'): + return hash(self.id) + else: + raise TypeError('unhashable type: {} (no id attribute)'.format(type(self))) class DirectMessage(Model):