projects
/
tweepy.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
e748758
)
make User object hashable to allow use with sets
author
mohammed chamma
<hms.mohammed@gmail.com>
Tue, 24 Dec 2019 03:18:01 +0000
(22:18 -0500)
committer
GitHub
<noreply@github.com>
Tue, 24 Dec 2019 03:18:01 +0000
(22:18 -0500)
this allows for one-liners like
```connections = list(set(followers) & set(friends))```
tweepy/models.py
patch
|
blob
|
blame
|
history
diff --git
a/tweepy/models.py
b/tweepy/models.py
index 7c33d8f52453d2d4c8f54d0fac35493af18da013..aceb398427a29fb212cb68347da0247ee7ac9c5b 100644
(file)
--- 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):