From 8f8de15e13f11d042a521d2adae24d0c09fa2098 Mon Sep 17 00:00:00 2001 From: Harmon Date: Mon, 25 Oct 2021 03:36:59 -0500 Subject: [PATCH] Rename Client.follow and Client.unfollow 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 --- ...aml => test_follow_and_unfollow_user.yaml} | 0 docs/client.rst | 4 +++ tests/test_client.py | 8 ++--- tweepy/client.py | 29 +++++++++++++++++-- 4 files changed, 35 insertions(+), 6 deletions(-) rename cassettes/{test_follow_and_unfollow.yaml => test_follow_and_unfollow_user.yaml} (100%) diff --git a/cassettes/test_follow_and_unfollow.yaml b/cassettes/test_follow_and_unfollow_user.yaml similarity index 100% rename from cassettes/test_follow_and_unfollow.yaml rename to cassettes/test_follow_and_unfollow_user.yaml diff --git a/docs/client.rst b/docs/client.rst index 4c3f6f7..3d7b562 100644 --- a/docs/client.rst +++ b/docs/client.rst @@ -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 diff --git a/tests/test_client.py b/tests/test_client.py index e708086..66bef3c 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -92,11 +92,11 @@ class TweepyTestCase(unittest.TestCase): 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): diff --git a/tweepy/client.py b/tweepy/client.py index 55aaf04..3678612 100644 --- a/tweepy/client.py +++ b/tweepy/client.py @@ -7,6 +7,7 @@ import datetime import logging from platform import python_version import time +import warnings import requests @@ -1192,7 +1193,7 @@ class Client: # 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 @@ -1218,6 +1219,18 @@ class Client: "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, \ @@ -1313,7 +1326,7 @@ class Client: ), 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 @@ -1344,6 +1357,18 @@ class Client: 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): -- 2.25.1