Skip to content

Commit

Permalink
Remove Deprecated Functionality (#2644)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibo-Joshi committed Sep 9, 2021
1 parent a717db8 commit 12fe042
Show file tree
Hide file tree
Showing 24 changed files with 41 additions and 1,064 deletions.
9 changes: 0 additions & 9 deletions docs/source/telegram.ext.delayqueue.rst

This file was deleted.

9 changes: 0 additions & 9 deletions docs/source/telegram.ext.messagequeue.rst

This file was deleted.

2 changes: 0 additions & 2 deletions docs/source/telegram.ext.rst
Expand Up @@ -10,8 +10,6 @@ telegram.ext package
telegram.ext.callbackcontext
telegram.ext.job
telegram.ext.jobqueue
telegram.ext.messagequeue
telegram.ext.delayqueue
telegram.ext.contexttypes
telegram.ext.defaults

Expand Down
93 changes: 5 additions & 88 deletions telegram/bot.py
Expand Up @@ -148,6 +148,11 @@ class Bot(TelegramObject):
incorporated into PTB. However, this is not guaranteed to work, i.e. it will fail for
passing files.
.. versionchanged:: 14.0
* Removed the deprecated methods ``kick_chat_member``, ``kickChatMember``,
``get_chat_members_count`` and ``getChatMembersCount``.
* Removed the deprecated property ``commands``.
Args:
token (:obj:`str`): Bot's unique authentication.
base_url (:obj:`str`, optional): Telegram Bot API service URL.
Expand All @@ -173,7 +178,6 @@ class Bot(TelegramObject):
'private_key',
'defaults',
'_bot',
'_commands',
'_request',
'logger',
)
Expand Down Expand Up @@ -209,7 +213,6 @@ def __init__(
self.base_url = str(base_url) + str(self.token)
self.base_file_url = str(base_file_url) + str(self.token)
self._bot: Optional[User] = None
self._commands: Optional[List[BotCommand]] = None
self._request = request or Request()
self.private_key = None
self.logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -391,26 +394,6 @@ def supports_inline_queries(self) -> bool:
""":obj:`bool`: Bot's :attr:`telegram.User.supports_inline_queries` attribute."""
return self.bot.supports_inline_queries # type: ignore

@property
def commands(self) -> List[BotCommand]:
"""
List[:class:`BotCommand`]: Bot's commands as available in the default scope.
.. deprecated:: 13.7
This property has been deprecated since there can be different commands available for
different scopes.
"""
warnings.warn(
"Bot.commands has been deprecated since there can be different command "
"lists for different scopes.",
TelegramDeprecationWarning,
stacklevel=2,
)

if self._commands is None:
self._commands = self.get_my_commands()
return self._commands

@property
def name(self) -> str:
""":obj:`str`: Bot's @username."""
Expand Down Expand Up @@ -2307,36 +2290,6 @@ def get_file(

return File.de_json(result, self) # type: ignore[return-value, arg-type]

@log
def kick_chat_member(
self,
chat_id: Union[str, int],
user_id: Union[str, int],
timeout: ODVInput[float] = DEFAULT_NONE,
until_date: Union[int, datetime] = None,
api_kwargs: JSONDict = None,
revoke_messages: bool = None,
) -> bool:
"""
Deprecated, use :func:`~telegram.Bot.ban_chat_member` instead.
.. deprecated:: 13.7
"""
warnings.warn(
'`bot.kick_chat_member` is deprecated. Use `bot.ban_chat_member` instead.',
TelegramDeprecationWarning,
stacklevel=2,
)
return self.ban_chat_member(
chat_id=chat_id,
user_id=user_id,
timeout=timeout,
until_date=until_date,
api_kwargs=api_kwargs,
revoke_messages=revoke_messages,
)

@log
def ban_chat_member(
self,
Expand Down Expand Up @@ -3091,26 +3044,6 @@ def get_chat_administrators(

return ChatMember.de_list(result, self) # type: ignore

@log
def get_chat_members_count(
self,
chat_id: Union[str, int],
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> int:
"""
Deprecated, use :func:`~telegram.Bot.get_chat_member_count` instead.
.. deprecated:: 13.7
"""
warnings.warn(
'`bot.get_chat_members_count` is deprecated. '
'Use `bot.get_chat_member_count` instead.',
TelegramDeprecationWarning,
stacklevel=2,
)
return self.get_chat_member_count(chat_id=chat_id, timeout=timeout, api_kwargs=api_kwargs)

@log
def get_chat_member_count(
self,
Expand Down Expand Up @@ -5064,10 +4997,6 @@ def get_my_commands(

result = self._post('getMyCommands', data, timeout=timeout, api_kwargs=api_kwargs)

if (scope is None or scope.type == scope.DEFAULT) and language_code is None:
self._commands = BotCommand.de_list(result, self) # type: ignore[assignment,arg-type]
return self._commands # type: ignore[return-value]

return BotCommand.de_list(result, self) # type: ignore[return-value,arg-type]

@log
Expand Down Expand Up @@ -5124,11 +5053,6 @@ def set_my_commands(

result = self._post('setMyCommands', data, timeout=timeout, api_kwargs=api_kwargs)

# Set commands only for default scope. No need to check for outcome.
# If request failed, we won't come this far
if (scope is None or scope.type == scope.DEFAULT) and language_code is None:
self._commands = cmds

return result # type: ignore[return-value]

@log
Expand Down Expand Up @@ -5176,9 +5100,6 @@ def delete_my_commands(

result = self._post('deleteMyCommands', data, timeout=timeout, api_kwargs=api_kwargs)

if (scope is None or scope.type == scope.DEFAULT) and language_code is None:
self._commands = []

return result # type: ignore[return-value]

@log
Expand Down Expand Up @@ -5370,8 +5291,6 @@ def __hash__(self) -> int:
"""Alias for :meth:`get_file`"""
banChatMember = ban_chat_member
"""Alias for :meth:`ban_chat_member`"""
kickChatMember = kick_chat_member
"""Alias for :meth:`kick_chat_member`"""
unbanChatMember = unban_chat_member
"""Alias for :meth:`unban_chat_member`"""
answerCallbackQuery = answer_callback_query
Expand Down Expand Up @@ -5404,8 +5323,6 @@ def __hash__(self) -> int:
"""Alias for :meth:`delete_chat_sticker_set`"""
getChatMemberCount = get_chat_member_count
"""Alias for :meth:`get_chat_member_count`"""
getChatMembersCount = get_chat_members_count
"""Alias for :meth:`get_chat_members_count`"""
getWebhookInfo = get_webhook_info
"""Alias for :meth:`get_webhook_info`"""
setGameScore = set_game_score
Expand Down
51 changes: 3 additions & 48 deletions telegram/chat.py
Expand Up @@ -18,13 +18,11 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Chat."""
import warnings
from datetime import datetime
from typing import TYPE_CHECKING, List, Optional, ClassVar, Union, Tuple, Any

from telegram import ChatPhoto, TelegramObject, constants
from telegram.utils.types import JSONDict, FileInput, ODVInput, DVInput
from telegram.utils.deprecate import TelegramDeprecationWarning

from .chatpermissions import ChatPermissions
from .chatlocation import ChatLocation
Expand Down Expand Up @@ -65,6 +63,9 @@ class Chat(TelegramObject):
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`id` is equal.
.. versionchanged:: 14.0
Removed the deprecated methods ``kick_member`` and ``get_members_count``.
Args:
id (:obj:`int`): Unique identifier for this chat. This number may be greater than 32 bits
and some programming languages may have difficulty/silent defects in interpreting it.
Expand Down Expand Up @@ -317,25 +318,6 @@ def get_administrators(
api_kwargs=api_kwargs,
)

def get_members_count(
self, timeout: ODVInput[float] = DEFAULT_NONE, api_kwargs: JSONDict = None
) -> int:
"""
Deprecated, use :func:`~telegram.Chat.get_member_count` instead.
.. deprecated:: 13.7
"""
warnings.warn(
'`Chat.get_members_count` is deprecated. Use `Chat.get_member_count` instead.',
TelegramDeprecationWarning,
stacklevel=2,
)

return self.get_member_count(
timeout=timeout,
api_kwargs=api_kwargs,
)

def get_member_count(
self, timeout: ODVInput[float] = DEFAULT_NONE, api_kwargs: JSONDict = None
) -> int:
Expand Down Expand Up @@ -378,33 +360,6 @@ def get_member(
api_kwargs=api_kwargs,
)

def kick_member(
self,
user_id: Union[str, int],
timeout: ODVInput[float] = DEFAULT_NONE,
until_date: Union[int, datetime] = None,
api_kwargs: JSONDict = None,
revoke_messages: bool = None,
) -> bool:
"""
Deprecated, use :func:`~telegram.Chat.ban_member` instead.
.. deprecated:: 13.7
"""
warnings.warn(
'`Chat.kick_member` is deprecated. Use `Chat.ban_member` instead.',
TelegramDeprecationWarning,
stacklevel=2,
)

return self.ban_member(
user_id=user_id,
timeout=timeout,
until_date=until_date,
api_kwargs=api_kwargs,
revoke_messages=revoke_messages,
)

def ban_member(
self,
user_id: Union[str, int],
Expand Down
18 changes: 5 additions & 13 deletions telegram/chataction.py
Expand Up @@ -23,17 +23,15 @@


class ChatAction:
"""Helper class to provide constants for different chat actions."""
"""Helper class to provide constants for different chat actions.
.. versionchanged:: 14.0
Removed the deprecated constants ``RECORD_AUDIO`` and ``UPLOAD_AUDIO``.
"""

__slots__ = ()
FIND_LOCATION: ClassVar[str] = constants.CHATACTION_FIND_LOCATION
""":const:`telegram.constants.CHATACTION_FIND_LOCATION`"""
RECORD_AUDIO: ClassVar[str] = constants.CHATACTION_RECORD_AUDIO
""":const:`telegram.constants.CHATACTION_RECORD_AUDIO`
.. deprecated:: 13.5
Deprecated by Telegram. Use :attr:`RECORD_VOICE` instead.
"""
RECORD_VOICE: ClassVar[str] = constants.CHATACTION_RECORD_VOICE
""":const:`telegram.constants.CHATACTION_RECORD_VOICE`
Expand All @@ -45,12 +43,6 @@ class ChatAction:
""":const:`telegram.constants.CHATACTION_RECORD_VIDEO_NOTE`"""
TYPING: ClassVar[str] = constants.CHATACTION_TYPING
""":const:`telegram.constants.CHATACTION_TYPING`"""
UPLOAD_AUDIO: ClassVar[str] = constants.CHATACTION_UPLOAD_AUDIO
""":const:`telegram.constants.CHATACTION_UPLOAD_AUDIO`
.. deprecated:: 13.5
Deprecated by Telegram. Use :attr:`UPLOAD_VOICE` instead.
"""
UPLOAD_VOICE: ClassVar[str] = constants.CHATACTION_UPLOAD_VOICE
""":const:`telegram.constants.CHATACTION_UPLOAD_VOICE`
Expand Down
12 changes: 3 additions & 9 deletions telegram/constants.py
Expand Up @@ -66,22 +66,18 @@
:class:`telegram.ChatAction`:
.. versionchanged:: 14.0
Removed the deprecated constants ``CHATACTION_RECORD_AUDIO`` and ``CHATACTION_UPLOAD_AUDIO``.
Attributes:
CHATACTION_FIND_LOCATION (:obj:`str`): ``'find_location'``
CHATACTION_RECORD_AUDIO (:obj:`str`): ``'record_audio'``
.. deprecated:: 13.5
Deprecated by Telegram. Use :const:`CHATACTION_RECORD_VOICE` instead.
CHATACTION_RECORD_VOICE (:obj:`str`): ``'record_voice'``
.. versionadded:: 13.5
CHATACTION_RECORD_VIDEO (:obj:`str`): ``'record_video'``
CHATACTION_RECORD_VIDEO_NOTE (:obj:`str`): ``'record_video_note'``
CHATACTION_TYPING (:obj:`str`): ``'typing'``
CHATACTION_UPLOAD_AUDIO (:obj:`str`): ``'upload_audio'``
.. deprecated:: 13.5
Deprecated by Telegram. Use :const:`CHATACTION_UPLOAD_VOICE` instead.
CHATACTION_UPLOAD_VOICE (:obj:`str`): ``'upload_voice'``
.. versionadded:: 13.5
Expand Down Expand Up @@ -259,12 +255,10 @@
CHAT_CHANNEL: str = 'channel'

CHATACTION_FIND_LOCATION: str = 'find_location'
CHATACTION_RECORD_AUDIO: str = 'record_audio'
CHATACTION_RECORD_VOICE: str = 'record_voice'
CHATACTION_RECORD_VIDEO: str = 'record_video'
CHATACTION_RECORD_VIDEO_NOTE: str = 'record_video_note'
CHATACTION_TYPING: str = 'typing'
CHATACTION_UPLOAD_AUDIO: str = 'upload_audio'
CHATACTION_UPLOAD_VOICE: str = 'upload_voice'
CHATACTION_UPLOAD_DOCUMENT: str = 'upload_document'
CHATACTION_UPLOAD_PHOTO: str = 'upload_photo'
Expand Down
7 changes: 1 addition & 6 deletions telegram/ext/__init__.py
Expand Up @@ -25,7 +25,7 @@
from .handler import Handler
from .callbackcontext import CallbackContext
from .contexttypes import ContextTypes
from .dispatcher import Dispatcher, DispatcherHandlerStop, run_async
from .dispatcher import Dispatcher, DispatcherHandlerStop

from .jobqueue import JobQueue, Job
from .updater import Updater
Expand All @@ -41,8 +41,6 @@
from .conversationhandler import ConversationHandler
from .precheckoutqueryhandler import PreCheckoutQueryHandler
from .shippingqueryhandler import ShippingQueryHandler
from .messagequeue import MessageQueue
from .messagequeue import DelayQueue
from .pollanswerhandler import PollAnswerHandler
from .pollhandler import PollHandler
from .chatmemberhandler import ChatMemberHandler
Expand All @@ -61,7 +59,6 @@
'ContextTypes',
'ConversationHandler',
'Defaults',
'DelayQueue',
'DictPersistence',
'Dispatcher',
'DispatcherHandlerStop',
Expand All @@ -74,7 +71,6 @@
'JobQueue',
'MessageFilter',
'MessageHandler',
'MessageQueue',
'PersistenceInput',
'PicklePersistence',
'PollAnswerHandler',
Expand All @@ -87,5 +83,4 @@
'TypeHandler',
'UpdateFilter',
'Updater',
'run_async',
)

0 comments on commit 12fe042

Please sign in to comment.