Skip to content

Commit bd7e6af

Browse files
committed
Merge pull request bear#314 from bear/kwargs-consistency
Consistency in keyword arguments for "id" parameters
2 parents 7968856 + 7dcdf61 commit bd7e6af

3 files changed

Lines changed: 91 additions & 50 deletions

File tree

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
help:
33
@echo " env install all production dependencies"
44
@echo " dev install all dev and production dependencies (virtualenv is assumed)"
5+
@echo " docs build documentation"
56
@echo " clean remove unwanted stuff"
67
@echo " lint check style with flake8"
78
@echo " test run tests"
@@ -23,7 +24,10 @@ clean:
2324
rm -fr dist
2425
find . -name '*.pyc' -exec rm -f {} \;
2526
find . -name '*.pyo' -exec rm -f {} \;
26-
find . -name '*~' -exec rm -f {} \;
27+
find . -name '*~' ! -name '*.un~' -exec rm -f {} \;
28+
29+
docs:
30+
$(MAKE) -C doc html
2731

2832
lint:
2933
flake8 twitter > violations.flake8.txt

doc/migration_v30.rst

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ Migration from v2 to v3
44
Changes to Existing Methods
55
===========================
66

7+
:py:func:`twitter.api.Api.CreateFavorite`
8+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9+
* kwarg param has been changed to ``status_id`` from ``id`` to be consistent
10+
with other method calls and avoid shadowing builtin function ``id``.
11+
12+
:py:func:`twitter.api.Api.DestroyFavorite`
13+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14+
* kwarg param has been changed to ``status_id`` from ``id`` to be consistent
15+
with other method calls and avoid shadowing builtin function ``id``.
16+
17+
:py:func:`twitter.api.Api.DestroyBlock`
18+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19+
* Kwarg ``id`` has been changed to ``user_id`` in order to avoid shadowing
20+
a builtin and be more descriptive.
21+
22+
:py:func:`twitter.api.Api.DestroyStatus`
23+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24+
* kwarg ``id`` has been changed to ``status_id`` in keeping with the rest of
25+
the Api and to avoid shadowing a builtin.
26+
727
:py:func:`twitter.api.Api.GetBlocks`
828
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
929
* Method no longer accepts parameters ``user_id`` or ``screen_name`` as these are not honored by Twitter. The data returned will be for the authenticated user only.
@@ -35,18 +55,32 @@ Changes to Existing Methods
3555
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3656
* No longer accepts ``cursor`` parameter. If you require granular control over the paging of the twitter.list.List members, please user twitter.api.Api.GetListMembersPaged instead.
3757

58+
:py:func:`twitter.api.Api.GetStatus`
59+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
60+
* Kwarg ``id`` has been changed to ``status_id`` in keeping with the rest of
61+
the Api and to avoid shadowing a builtin.
62+
63+
:py:func:`twitter.api.Api.GetStatusOembed`
64+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
65+
* Kwarg ``id`` has been changed to ``status_id`` in keeping with the rest of
66+
the Api and to avoid shadowing a builtin.
67+
3868
:py:func:`twitter.api.Api.GetSearch`
3969
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4070
* Adds ``raw_query`` method. See :ref:`raw_queries` for more information.
4171

72+
73+
:py:func:`twitter.api.Api.GetTrendsWoeid`
74+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
75+
* Kwarg ``id`` has been changed to ``woeid`` in order to avoid shadowing
76+
a builtin and be more descriptive.
77+
4278
:py:func:`twitter.api.Api.GetUserStream`
4379
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4480
* Parameter 'stall_warning' is now 'stall_warnings' in line with GetStreamFilter and Twitter's naming convention. This should now actually return stall warnings, whereas it did not have any effect previously.
4581

46-
4782
:py:func:`twitter.api.Api.LookupFriendship`
4883
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
49-
5084
* Method will now accept a list for either ``user_id`` or ``screen_name``. The list can contain either ints, strings, or :py:mod:`twitter.user.User` objects for either ``user_id`` or ``screen_name``.
5185
* Return value is a list of :py:mod:`twitter.user.UserStatus` objects.
5286

@@ -56,6 +90,10 @@ Changes to Existing Methods
5690
* ``media_additional_owners`` should be a list of user ids representing Twitter users that should be able to use the uploaded media in their tweets. If you pass a list of media, then **additional owners will apply to each object.** If you need more granular control, please use the UploadMedia* methods.
5791
* ``media_category``: Only for use with the AdsAPI. See https://dev.twitter.com/ads/creative/promoted-video-overview if this applies to your application.
5892

93+
:py:func:`twitter.api.Api.PostRetweet`
94+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
95+
* Kwarg ``original_id`` has been changed to ``status_id`` in order to avoid shadowing
96+
a builtin and be more descriptive.
5997

6098
Deprecation
6199
===========

twitter/api.py

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
22

33
#
4-
# vim: sw=2 ts=2 sts=2
54
#
65
# Copyright 2007 The Python-Twitter Developers
76
#
@@ -107,15 +106,15 @@ class Api(object):
107106
>>> api.GetReplies()
108107
>>> api.GetUserTimeline(user)
109108
>>> api.GetHomeTimeline()
110-
>>> api.GetStatus(id)
111-
>>> api.DestroyStatus(id)
109+
>>> api.GetStatus(status_id)
110+
>>> api.DestroyStatus(status_id)
112111
>>> api.GetFriends(user)
113112
>>> api.GetFollowers()
114113
>>> api.GetFeatured()
115114
>>> api.GetDirectMessages()
116115
>>> api.GetSentDirectMessages()
117116
>>> api.PostDirectMessage(user, text)
118-
>>> api.DestroyDirectMessage(id)
117+
>>> api.DestroyDirectMessage(message_id)
119118
>>> api.DestroyFriendship(user)
120119
>>> api.CreateFriendship(user)
121120
>>> api.LookupFriendship(user)
@@ -490,9 +489,9 @@ def GetTrendsCurrent(self, exclude=None):
490489
Returns:
491490
A list with 10 entries. Each entry contains a trend.
492491
"""
493-
return self.GetTrendsWoeid(id=1, exclude=exclude)
492+
return self.GetTrendsWoeid(woeid=1, exclude=exclude)
494493

495-
def GetTrendsWoeid(self, id, exclude=None):
494+
def GetTrendsWoeid(self, woeid, exclude=None):
496495
"""Return the top 10 trending topics for a specific WOEID, if trending
497496
information is available for it.
498497
@@ -507,7 +506,7 @@ def GetTrendsWoeid(self, id, exclude=None):
507506
A list with 10 entries. Each entry contains a trend.
508507
"""
509508
url = '%s/trends/place.json' % (self.base_url)
510-
parameters = {'id': id}
509+
parameters = {'id': woeid}
511510

512511
if exclude:
513512
parameters['exclude'] = exclude
@@ -723,14 +722,14 @@ def GetUserTimeline(self,
723722
return [Status.NewFromJsonDict(x) for x in data]
724723

725724
def GetStatus(self,
726-
id,
725+
status_id,
727726
trim_user=False,
728727
include_my_retweet=True,
729728
include_entities=True):
730-
"""Returns a single status message, specified by the id parameter.
729+
"""Returns a single status message, specified by the status_id parameter.
731730
732731
Args:
733-
id:
732+
status_id:
734733
The numeric ID of the status you are trying to retrieve.
735734
trim_user:
736735
When set to True, each tweet returned in a timeline will include
@@ -754,9 +753,9 @@ def GetStatus(self,
754753
parameters = {}
755754

756755
try:
757-
parameters['id'] = int(id)
756+
parameters['id'] = int(status_id)
758757
except ValueError:
759-
raise TwitterError({'message': "'id' must be an integer."})
758+
raise TwitterError({'message': "'status_id' must be an integer."})
760759

761760
if trim_user:
762761
parameters['trim_user'] = 1
@@ -771,7 +770,7 @@ def GetStatus(self,
771770
return Status.NewFromJsonDict(data)
772771

773772
def GetStatusOembed(self,
774-
id=None,
773+
status_id=None,
775774
url=None,
776775
maxwidth=None,
777776
hide_media=False,
@@ -786,7 +785,7 @@ def GetStatusOembed(self,
786785
Specify tweet by the id or url parameter.
787786
788787
Args:
789-
id:
788+
status_id:
790789
The numeric ID of the status you are trying to embed.
791790
url:
792791
The url of the status you are trying to embed.
@@ -816,15 +815,15 @@ def GetStatusOembed(self,
816815

817816
parameters = {}
818817

819-
if id is not None:
818+
if status_id is not None:
820819
try:
821-
parameters['id'] = int(id)
820+
parameters['id'] = int(status_id)
822821
except ValueError:
823-
raise TwitterError({'message': "'id' must be an integer."})
822+
raise TwitterError({'message': "'status_id' must be an integer."})
824823
elif url is not None:
825824
parameters['url'] = url
826825
else:
827-
raise TwitterError({'message': "Must specify either 'id' or 'url'"})
826+
raise TwitterError({'message': "Must specify either 'status_id' or 'url'"})
828827

829828
if maxwidth is not None:
830829
parameters['maxwidth'] = maxwidth
@@ -852,24 +851,24 @@ def GetStatusOembed(self,
852851

853852
return data
854853

855-
def DestroyStatus(self, id, trim_user=False):
854+
def DestroyStatus(self, status_id, trim_user=False):
856855
"""Destroys the status specified by the required ID parameter.
857856
858857
The authenticating user must be the author of the specified
859858
status.
860859
861860
Args:
862-
id:
861+
status_id:
863862
The numerical ID of the status you're trying to destroy.
864863
865864
Returns:
866865
A twitter.Status instance representing the destroyed status message
867866
"""
868867
try:
869-
post_data = {'id': int(id)}
868+
post_data = {'id': int(status_id)}
870869
except ValueError:
871-
raise TwitterError({'message': "id must be an integer"})
872-
url = '%s/statuses/destroy/%s.json' % (self.base_url, id)
870+
raise TwitterError({'message': "status_id must be an integer"})
871+
url = '%s/statuses/destroy/%s.json' % (self.base_url, status_id)
873872
if trim_user:
874873
post_data['trim_user'] = 1
875874

@@ -1406,11 +1405,11 @@ def PostUpdates(self,
14061405

14071406
return results
14081407

1409-
def PostRetweet(self, original_id, trim_user=False):
1408+
def PostRetweet(self, status_id, trim_user=False):
14101409
"""Retweet a tweet with the Retweet API.
14111410
14121411
Args:
1413-
original_id:
1412+
status_id:
14141413
The numerical id of the tweet that will be retweeted
14151414
trim_user:
14161415
If True the returned payload will only contain the user IDs,
@@ -1421,13 +1420,13 @@ def PostRetweet(self, original_id, trim_user=False):
14211420
A twitter.Status instance representing the original tweet with retweet details embedded.
14221421
"""
14231422
try:
1424-
if int(original_id) <= 0:
1425-
raise TwitterError({'message': "'original_id' must be a positive number"})
1423+
if int(status_id) <= 0:
1424+
raise TwitterError({'message': "'status_id' must be a positive number"})
14261425
except ValueError:
1427-
raise TwitterError({'message': "'original_id' must be an integer"})
1426+
raise TwitterError({'message': "'status_id' must be an integer"})
14281427

1429-
url = '%s/statuses/retweet/%s.json' % (self.base_url, original_id)
1430-
data = {'id': original_id}
1428+
url = '%s/statuses/retweet/%s.json' % (self.base_url, status_id)
1429+
data = {'id': status_id}
14311430
if trim_user:
14321431
data['trim_user'] = 'true'
14331432
resp = self._RequestUrl(url, 'POST', data=data)
@@ -1771,24 +1770,24 @@ def GetBlocksIDs(self,
17711770

17721771
return result
17731772

1774-
def DestroyBlock(self, id, trim_user=False):
1773+
def DestroyBlock(self, user_id, trim_user=False):
17751774
"""Destroys the block for the user specified by the required ID
17761775
parameter.
17771776
17781777
The authenticating user must have blocked the user specified by the
17791778
required ID parameter.
17801779
17811780
Args:
1782-
id:
1781+
user_id:
17831782
The numerical ID of the user to be un-blocked.
17841783
17851784
Returns:
17861785
A twitter.User instance representing the un-blocked user.
17871786
"""
17881787
try:
1789-
post_data = {'user_id': int(id)}
1788+
post_data = {'user_id': int(user_id)}
17901789
except ValueError:
1791-
raise TwitterError({'message': "id must be an integer"})
1790+
raise TwitterError({'message': "user_id must be an integer"})
17921791
url = '%s/blocks/destroy.json' % (self.base_url)
17931792
if trim_user:
17941793
post_data['trim_user'] = 1
@@ -2640,21 +2639,21 @@ def PostDirectMessage(self,
26402639

26412640
return DirectMessage.NewFromJsonDict(data)
26422641

2643-
def DestroyDirectMessage(self, id, include_entities=True):
2642+
def DestroyDirectMessage(self, message_id, include_entities=True):
26442643
"""Destroys the direct message specified in the required ID parameter.
26452644
26462645
The twitter.Api instance must be authenticated, and the
26472646
authenticating user must be the recipient of the specified direct
26482647
message.
26492648
26502649
Args:
2651-
id: The id of the direct message to be destroyed
2650+
message_id: The id of the direct message to be destroyed
26522651
26532652
Returns:
26542653
A twitter.DirectMessage instance representing the message destroyed
26552654
"""
26562655
url = '%s/direct_messages/destroy.json' % self.base_url
2657-
data = {'id': id}
2656+
data = {'id': message_id}
26582657
if not include_entities:
26592658
data['include_entities'] = 'false'
26602659

@@ -2810,14 +2809,14 @@ def LookupFriendship(self,
28102809

28112810
def CreateFavorite(self,
28122811
status=None,
2813-
id=None,
2812+
status_id=None,
28142813
include_entities=True):
28152814
"""Favorites the specified status object or id as the authenticating user.
28162815
28172816
Returns the favorite status when successful.
28182817
28192818
Args:
2820-
id:
2819+
status_id:
28212820
The id of the twitter status to mark as a favorite. [Optional]
28222821
status:
28232822
The twitter.Status object to mark as a favorite. [Optional]
@@ -2829,12 +2828,12 @@ def CreateFavorite(self,
28292828
"""
28302829
url = '%s/favorites/create.json' % self.base_url
28312830
data = {}
2832-
if id:
2833-
data['id'] = id
2831+
if status_id:
2832+
data['id'] = status_id
28342833
elif status:
28352834
data['id'] = status.id
28362835
else:
2837-
raise TwitterError({'message': "Specify id or status"})
2836+
raise TwitterError({'message': "Specify status_id or status"})
28382837
if not include_entities:
28392838
data['include_entities'] = 'false'
28402839

@@ -2845,14 +2844,14 @@ def CreateFavorite(self,
28452844

28462845
def DestroyFavorite(self,
28472846
status=None,
2848-
id=None,
2847+
status_id=None,
28492848
include_entities=True):
28502849
"""Un-Favorites the specified status object or id as the authenticating user.
28512850
28522851
Returns the un-favorited status when successful.
28532852
28542853
Args:
2855-
id:
2854+
status_id:
28562855
The id of the twitter status to unmark as a favorite. [Optional]
28572856
status:
28582857
The twitter.Status object to unmark as a favorite. [Optional]
@@ -2864,12 +2863,12 @@ def DestroyFavorite(self,
28642863
"""
28652864
url = '%s/favorites/destroy.json' % self.base_url
28662865
data = {}
2867-
if id:
2868-
data['id'] = id
2866+
if status_id:
2867+
data['id'] = status_id
28692868
elif status:
28702869
data['id'] = status.id
28712870
else:
2872-
raise TwitterError({'message': "Specify id or status"})
2871+
raise TwitterError({'message': "Specify status_id or status"})
28732872
if not include_entities:
28742873
data['include_entities'] = 'false'
28752874

0 commit comments

Comments
 (0)