Skip to content

Commit

Permalink
Rename Client.follow and Client.unfollow
Browse files Browse the repository at this point in the history
Rename Client.follow and Client.unfollow to Client.follow_user and Client.unfollow_user, respectively
Client.follow and Client.unfollow are kept as deprecated aliases
  • Loading branch information
Harmon758 committed Oct 25, 2021
1 parent 6606f83 commit 8f8de15
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
File renamed without changes.
4 changes: 4 additions & 0 deletions docs/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ Blocks
Follows
-------

.. automethod:: Client.unfollow_user

.. automethod:: Client.unfollow

.. automethod:: Client.get_users_followers

.. automethod:: Client.get_users_following

.. automethod:: Client.follow_user

.. automethod:: Client.follow

Mutes
Expand Down
8 changes: 4 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ def test_block_and_unblock(self):
self.client.get_blocked()
self.client.unblock(user_id)

@tape.use_cassette("test_follow_and_unfollow.yaml", serializer="yaml")
def test_follow_and_unfollow(self):
@tape.use_cassette("test_follow_and_unfollow_user.yaml", serializer="yaml")
def test_follow_and_unfollow_user(self):
user_id = 17874544 # User ID for @TwitterSupport
self.client.follow(user_id)
self.client.unfollow(user_id)
self.client.follow_user(user_id)
self.client.unfollow_user(user_id)

@tape.use_cassette("test_get_users_followers.yaml", serializer="yaml")
def test_get_users_followers(self):
Expand Down
29 changes: 27 additions & 2 deletions tweepy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
from platform import python_version
import time
import warnings

import requests

Expand Down Expand Up @@ -1192,7 +1193,7 @@ def block(self, target_user_id):

# Follows

def unfollow(self, target_user_id):
def unfollow_user(self, target_user_id):
"""Allows a user ID to unfollow another user.
The request succeeds with no action when the authenticated user sends a
Expand All @@ -1218,6 +1219,18 @@ def unfollow(self, target_user_id):
"DELETE", route, user_auth=True
)

def unfollow(self, target_user_id):
"""Alias for :meth:`Client.unfollow_user`
.. deprecated:: 4.2
Use :meth:`Client.unfollow_user` instead.
"""
warnings.warn(
"Client.unfollow is deprecated; use Client.unfollow_user instead.",
DeprecationWarning
)
self.unfollow_user(target_user_id)

def get_users_followers(self, id, *, user_auth=False, **params):
"""get_users_followers( \
id, *, user_auth=False, expansions, max_results, \
Expand Down Expand Up @@ -1313,7 +1326,7 @@ def get_users_following(self, id, *, user_auth=False, **params):
), data_type=User, user_auth=user_auth
)

def follow(self, target_user_id):
def follow_user(self, target_user_id):
"""Allows a user ID to follow another user.
If the target user does not have public Tweets, this endpoint will send
Expand Down Expand Up @@ -1344,6 +1357,18 @@ def follow(self, target_user_id):
user_auth=True
)

def follow(self, target_user_id):
"""Alias for :meth:`Client.follow_user`
.. deprecated:: 4.2
Use :meth:`Client.follow_user` instead.
"""
warnings.warn(
"Client.follow is deprecated; use Client.follow_user instead.",
DeprecationWarning
)
self.follow_user(target_user_id)

# Mutes

def unmute(self, target_user_id):
Expand Down

0 comments on commit 8f8de15

Please sign in to comment.