Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit ab26ac0

Browse files
committed
move UserStatus.connections to private class attr
bc US.connections is a public variable, there is some confusion regarding its use. the original idea was that US.connections would only hold the default connection types available, much like the param_defaults attribute for other models; however, bc of the name, it was implied that this attribute contained the connections for the specific instance, resulting in confusion between it and the intended attributes (i.e., us.followed_by etc). this commit moves the attribute to a private attribute (._connections) so that it is clearer to end-users that it should not be used for a specific instance. additionally, this creates a @Property with the class-specific attributes for US.following, etc.
1 parent 8c5a036 commit ab26ac0

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

twitter/models.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@ class UserStatus(TwitterModel):
282282
""" A class representing the UserStatus structure. This is an abbreviated
283283
form of the twitter.User object. """
284284

285-
connections = {'following': False,
286-
'followed_by': False,
287-
'following_received': False,
288-
'following_requested': False,
289-
'blocking': False,
290-
'muting': False}
285+
_connections = {'following': False,
286+
'followed_by': False,
287+
'following_received': False,
288+
'following_requested': False,
289+
'blocking': False,
290+
'muting': False}
291291

292292
def __init__(self, **kwargs):
293293
self.param_defaults = {
@@ -307,12 +307,21 @@ def __init__(self, **kwargs):
307307
setattr(self, param, kwargs.get(param, default))
308308

309309
if 'connections' in kwargs:
310-
for param in self.connections:
310+
for param in self._connections:
311311
if param in kwargs['connections']:
312312
setattr(self, param, True)
313313

314+
@property
315+
def connections(self):
316+
return {'following': self.following,
317+
'followed_by': self.followed_by,
318+
'following_received': self.following_received,
319+
'following_requested': self.following_requested,
320+
'blocking': self.blocking,
321+
'muting': self.muting}
322+
314323
def __repr__(self):
315-
connections = [param for param in self.connections if getattr(self, param)]
324+
connections = [param for param in self._connections if getattr(self, param)]
316325
return "UserStatus(ID={uid}, ScreenName={sn}, Connections=[{conn}])".format(
317326
uid=self.id,
318327
sn=self.screen_name,

0 commit comments

Comments
 (0)