From a0355a5cc44cd6a8f86298f635a1f64345317a9f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Dec 2018 15:59:15 +0100 Subject: [PATCH] Type hint all methods return values --- pyrogram/client/methods/chats/delete_chat_photo.py | 2 +- .../client/methods/chats/export_chat_invite_link.py | 2 +- pyrogram/client/methods/chats/get_chat.py | 2 +- pyrogram/client/methods/chats/get_chat_member.py | 11 ++--------- pyrogram/client/methods/chats/get_chat_members.py | 2 +- .../client/methods/chats/get_chat_members_count.py | 2 +- pyrogram/client/methods/chats/get_dialogs.py | 2 +- pyrogram/client/methods/chats/kick_chat_member.py | 2 +- pyrogram/client/methods/chats/pin_chat_message.py | 2 +- pyrogram/client/methods/chats/promote_chat_member.py | 2 +- pyrogram/client/methods/chats/restrict_chat_member.py | 2 +- pyrogram/client/methods/chats/set_chat_description.py | 2 +- pyrogram/client/methods/chats/set_chat_photo.py | 2 +- pyrogram/client/methods/chats/set_chat_title.py | 2 +- pyrogram/client/methods/chats/unban_chat_member.py | 2 +- pyrogram/client/methods/chats/unpin_chat_message.py | 2 +- .../client/methods/decorators/on_callback_query.py | 7 +++++-- .../client/methods/decorators/on_deleted_messages.py | 7 +++++-- pyrogram/client/methods/decorators/on_disconnect.py | 5 +++-- pyrogram/client/methods/decorators/on_message.py | 2 +- pyrogram/client/methods/decorators/on_raw_update.py | 7 +++++-- pyrogram/client/methods/decorators/on_user_status.py | 7 +++++-- pyrogram/client/methods/messages/delete_messages.py | 2 +- .../client/methods/messages/edit_message_caption.py | 2 +- .../client/methods/messages/edit_message_media.py | 2 +- .../methods/messages/edit_message_reply_markup.py | 2 +- pyrogram/client/methods/messages/edit_message_text.py | 2 +- pyrogram/client/methods/messages/forward_messages.py | 10 +++++++--- pyrogram/client/methods/messages/get_messages.py | 2 +- pyrogram/client/methods/messages/send_animation.py | 2 +- pyrogram/client/methods/messages/send_audio.py | 2 +- pyrogram/client/methods/messages/send_contact.py | 2 +- pyrogram/client/methods/messages/send_document.py | 2 +- pyrogram/client/methods/messages/send_location.py | 2 +- pyrogram/client/methods/messages/send_message.py | 2 +- pyrogram/client/methods/messages/send_photo.py | 2 +- pyrogram/client/methods/messages/send_sticker.py | 2 +- pyrogram/client/methods/messages/send_venue.py | 2 +- pyrogram/client/methods/messages/send_video.py | 2 +- pyrogram/client/methods/messages/send_video_note.py | 2 +- pyrogram/client/methods/messages/send_voice.py | 2 +- .../client/methods/password/change_cloud_password.py | 2 +- .../client/methods/password/enable_cloud_password.py | 2 +- .../client/methods/password/remove_cloud_password.py | 2 +- .../methods/users/delete_user_profile_photos.py | 2 +- pyrogram/client/methods/users/get_me.py | 2 +- .../client/methods/users/get_user_profile_photos.py | 2 +- pyrogram/client/methods/users/get_users.py | 8 ++++---- .../client/methods/users/set_user_profile_photo.py | 2 +- pyrogram/client/methods/utilities/download_media.py | 2 +- pyrogram/client/types/user_and_chats/chat_member.py | 2 ++ 51 files changed, 80 insertions(+), 68 deletions(-) diff --git a/pyrogram/client/methods/chats/delete_chat_photo.py b/pyrogram/client/methods/chats/delete_chat_photo.py index d4658e4d..a33cae05 100644 --- a/pyrogram/client/methods/chats/delete_chat_photo.py +++ b/pyrogram/client/methods/chats/delete_chat_photo.py @@ -24,7 +24,7 @@ from ...ext import BaseClient class DeleteChatPhoto(BaseClient): def delete_chat_photo(self, - chat_id: Union[int, str]): + chat_id: Union[int, str]) -> bool: """Use this method to delete a chat photo. Photos can't be changed for private chats. You must be an administrator in the chat for this to work and must have the appropriate admin rights. diff --git a/pyrogram/client/methods/chats/export_chat_invite_link.py b/pyrogram/client/methods/chats/export_chat_invite_link.py index 8f068586..f458e91e 100644 --- a/pyrogram/client/methods/chats/export_chat_invite_link.py +++ b/pyrogram/client/methods/chats/export_chat_invite_link.py @@ -24,7 +24,7 @@ from ...ext import BaseClient class ExportChatInviteLink(BaseClient): def export_chat_invite_link(self, - chat_id: Union[int, str]): + chat_id: Union[int, str]) -> str: """Use this method to generate a new invite link for a chat; any previously generated link is revoked. You must be an administrator in the chat for this to work and have the appropriate admin rights. diff --git a/pyrogram/client/methods/chats/get_chat.py b/pyrogram/client/methods/chats/get_chat.py index 24651d37..f5bf19a9 100644 --- a/pyrogram/client/methods/chats/get_chat.py +++ b/pyrogram/client/methods/chats/get_chat.py @@ -25,7 +25,7 @@ from ...ext import BaseClient class GetChat(BaseClient): def get_chat(self, - chat_id: Union[int, str]): + chat_id: Union[int, str]) -> "pyrogram.Chat": """Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.) diff --git a/pyrogram/client/methods/chats/get_chat_member.py b/pyrogram/client/methods/chats/get_chat_member.py index 7708f6fc..9f13eac2 100644 --- a/pyrogram/client/methods/chats/get_chat_member.py +++ b/pyrogram/client/methods/chats/get_chat_member.py @@ -26,7 +26,7 @@ from ...ext import BaseClient class GetChatMember(BaseClient): def get_chat_member(self, chat_id: Union[int, str], - user_id: Union[int, str]): + user_id: Union[int, str]) -> "pyrogram.ChatMember": """Use this method to get information about one member of a chat. Args: @@ -67,13 +67,6 @@ class GetChatMember(BaseClient): ) ) - return pyrogram.ChatMembers._parse( - self, - types.channels.ChannelParticipants( - count=1, - participants=[r.participant], - users=r.users - ) - ).chat_members[0] + return pyrogram.ChatMember._parse(self, r.participant, r.users[0]) else: raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id)) diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index 031ea46b..8173423b 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -38,7 +38,7 @@ class GetChatMembers(BaseClient): offset: int = 0, limit: int = 200, query: str = "", - filter: str = Filters.ALL): + filter: str = Filters.ALL) -> "pyrogram.ChatMembers": """Use this method to get the members list of a chat. A chat can be either a basic group, a supergroup or a channel. diff --git a/pyrogram/client/methods/chats/get_chat_members_count.py b/pyrogram/client/methods/chats/get_chat_members_count.py index 01bbd835..37eb69cb 100644 --- a/pyrogram/client/methods/chats/get_chat_members_count.py +++ b/pyrogram/client/methods/chats/get_chat_members_count.py @@ -24,7 +24,7 @@ from ...ext import BaseClient class GetChatMembersCount(BaseClient): def get_chat_members_count(self, - chat_id: Union[int, str]): + chat_id: Union[int, str]) -> int: """Use this method to get the number of members in a chat. Args: diff --git a/pyrogram/client/methods/chats/get_dialogs.py b/pyrogram/client/methods/chats/get_dialogs.py index 87cd5be2..0e04423c 100644 --- a/pyrogram/client/methods/chats/get_dialogs.py +++ b/pyrogram/client/methods/chats/get_dialogs.py @@ -25,7 +25,7 @@ class GetDialogs(BaseClient): def get_dialogs(self, offset_dialog: "pyrogram.Dialog" = None, limit: int = 100, - pinned_only: bool = False): + pinned_only: bool = False) -> "pyrogram.Dialogs": """Use this method to get the user's dialogs You can get up to 100 dialogs at once. diff --git a/pyrogram/client/methods/chats/kick_chat_member.py b/pyrogram/client/methods/chats/kick_chat_member.py index a7459110..4ea4d6bb 100644 --- a/pyrogram/client/methods/chats/kick_chat_member.py +++ b/pyrogram/client/methods/chats/kick_chat_member.py @@ -27,7 +27,7 @@ class KickChatMember(BaseClient): def kick_chat_member(self, chat_id: Union[int, str], user_id: Union[int, str], - until_date: int = 0): + until_date: int = 0) -> "pyrogram.Message": """Use this method to kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. You must be an administrator in the chat for this to work and must diff --git a/pyrogram/client/methods/chats/pin_chat_message.py b/pyrogram/client/methods/chats/pin_chat_message.py index 1ef07d34..5a4ab50d 100644 --- a/pyrogram/client/methods/chats/pin_chat_message.py +++ b/pyrogram/client/methods/chats/pin_chat_message.py @@ -26,7 +26,7 @@ class PinChatMessage(BaseClient): def pin_chat_message(self, chat_id: Union[int, str], message_id: int, - disable_notification: bool = None): + disable_notification: bool = None) -> bool: """Use this method to pin a message in a supergroup or a channel. You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin right in the supergroup or "can_edit_messages" admin right in the channel. diff --git a/pyrogram/client/methods/chats/promote_chat_member.py b/pyrogram/client/methods/chats/promote_chat_member.py index d22a8ea7..18453b58 100644 --- a/pyrogram/client/methods/chats/promote_chat_member.py +++ b/pyrogram/client/methods/chats/promote_chat_member.py @@ -33,7 +33,7 @@ class PromoteChatMember(BaseClient): can_invite_users: bool = True, can_restrict_members: bool = True, can_pin_messages: bool = False, - can_promote_members: bool = False): + can_promote_members: bool = False) -> bool: """Use this method to promote or demote a user in a supergroup or a channel. You must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user. diff --git a/pyrogram/client/methods/chats/restrict_chat_member.py b/pyrogram/client/methods/chats/restrict_chat_member.py index c772d100..f9670250 100644 --- a/pyrogram/client/methods/chats/restrict_chat_member.py +++ b/pyrogram/client/methods/chats/restrict_chat_member.py @@ -30,7 +30,7 @@ class RestrictChatMember(BaseClient): can_send_messages: bool = False, can_send_media_messages: bool = False, can_send_other_messages: bool = False, - can_add_web_page_previews: bool = False): + can_add_web_page_previews: bool = False) -> bool: """Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift restrictions from a user. diff --git a/pyrogram/client/methods/chats/set_chat_description.py b/pyrogram/client/methods/chats/set_chat_description.py index 1606fe7e..7cf91da5 100644 --- a/pyrogram/client/methods/chats/set_chat_description.py +++ b/pyrogram/client/methods/chats/set_chat_description.py @@ -25,7 +25,7 @@ from ...ext import BaseClient class SetChatDescription(BaseClient): def set_chat_description(self, chat_id: Union[int, str], - description: str): + description: str) -> bool: """Use this method to change the description of a supergroup or a channel. You must be an administrator in the chat for this to work and must have the appropriate admin rights. diff --git a/pyrogram/client/methods/chats/set_chat_photo.py b/pyrogram/client/methods/chats/set_chat_photo.py index ed058000..1d4ab5e5 100644 --- a/pyrogram/client/methods/chats/set_chat_photo.py +++ b/pyrogram/client/methods/chats/set_chat_photo.py @@ -28,7 +28,7 @@ from ...ext import BaseClient class SetChatPhoto(BaseClient): def set_chat_photo(self, chat_id: Union[int, str], - photo: str): + photo: str) -> bool: """Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. You must be an administrator in the chat for this to work and must have the appropriate admin rights. diff --git a/pyrogram/client/methods/chats/set_chat_title.py b/pyrogram/client/methods/chats/set_chat_title.py index 58d4179c..af2b6e77 100644 --- a/pyrogram/client/methods/chats/set_chat_title.py +++ b/pyrogram/client/methods/chats/set_chat_title.py @@ -25,7 +25,7 @@ from ...ext import BaseClient class SetChatTitle(BaseClient): def set_chat_title(self, chat_id: Union[int, str], - title: str): + title: str) -> bool: """Use this method to change the title of a chat. Titles can't be changed for private chats. You must be an administrator in the chat for this to work and must have the appropriate admin rights. diff --git a/pyrogram/client/methods/chats/unban_chat_member.py b/pyrogram/client/methods/chats/unban_chat_member.py index 428e6fe8..3513f38d 100644 --- a/pyrogram/client/methods/chats/unban_chat_member.py +++ b/pyrogram/client/methods/chats/unban_chat_member.py @@ -25,7 +25,7 @@ from ...ext import BaseClient class UnbanChatMember(BaseClient): def unban_chat_member(self, chat_id: Union[int, str], - user_id: Union[int, str]): + user_id: Union[int, str]) -> bool: """Use this method to unban a previously kicked user in a supergroup or channel. The user will **not** return to the group or channel automatically, but will be able to join via link, etc. You must be an administrator for this to work. diff --git a/pyrogram/client/methods/chats/unpin_chat_message.py b/pyrogram/client/methods/chats/unpin_chat_message.py index bd6a22f8..435f38d7 100644 --- a/pyrogram/client/methods/chats/unpin_chat_message.py +++ b/pyrogram/client/methods/chats/unpin_chat_message.py @@ -24,7 +24,7 @@ from ...ext import BaseClient class UnpinChatMessage(BaseClient): def unpin_chat_message(self, - chat_id: Union[int, str]): + chat_id: Union[int, str]) -> bool: """Use this method to unpin a message in a supergroup or a channel. You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin right in the supergroup or "can_edit_messages" admin right in the channel. diff --git a/pyrogram/client/methods/decorators/on_callback_query.py b/pyrogram/client/methods/decorators/on_callback_query.py index f34119e2..8c152706 100644 --- a/pyrogram/client/methods/decorators/on_callback_query.py +++ b/pyrogram/client/methods/decorators/on_callback_query.py @@ -16,15 +16,18 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Tuple + import pyrogram from pyrogram.client.filters.filter import Filter +from pyrogram.client.handlers.handler import Handler from ...ext import BaseClient class OnCallbackQuery(BaseClient): def on_callback_query(self=None, filters=None, - group: int = 0): + group: int = 0) -> callable: """Use this decorator to automatically register a function for handling callback queries. This does the same thing as :meth:`add_handler` using the :class:`CallbackQueryHandler`. @@ -45,7 +48,7 @@ class OnCallbackQuery(BaseClient): The group identifier, defaults to 0. """ - def decorator(func): + def decorator(func: callable) -> Tuple[Handler, int]: if isinstance(func, tuple): func = func[0].callback diff --git a/pyrogram/client/methods/decorators/on_deleted_messages.py b/pyrogram/client/methods/decorators/on_deleted_messages.py index 406563f2..84abc92e 100644 --- a/pyrogram/client/methods/decorators/on_deleted_messages.py +++ b/pyrogram/client/methods/decorators/on_deleted_messages.py @@ -16,15 +16,18 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Tuple + import pyrogram from pyrogram.client.filters.filter import Filter +from pyrogram.client.handlers.handler import Handler from ...ext import BaseClient class OnDeletedMessages(BaseClient): def on_deleted_messages(self=None, filters=None, - group: int = 0): + group: int = 0) -> callable: """Use this decorator to automatically register a function for handling deleted messages. This does the same thing as :meth:`add_handler` using the :class:`DeletedMessagesHandler`. @@ -45,7 +48,7 @@ class OnDeletedMessages(BaseClient): The group identifier, defaults to 0. """ - def decorator(func): + def decorator(func: callable) -> Tuple[Handler, int]: if isinstance(func, tuple): func = func[0].callback diff --git a/pyrogram/client/methods/decorators/on_disconnect.py b/pyrogram/client/methods/decorators/on_disconnect.py index e2288619..56796bf5 100644 --- a/pyrogram/client/methods/decorators/on_disconnect.py +++ b/pyrogram/client/methods/decorators/on_disconnect.py @@ -17,17 +17,18 @@ # along with Pyrogram. If not, see . import pyrogram +from pyrogram.client.handlers.handler import Handler from ...ext import BaseClient class OnDisconnect(BaseClient): - def on_disconnect(self=None): + def on_disconnect(self=None) -> callable: """Use this decorator to automatically register a function for handling disconnections. This does the same thing as :meth:`add_handler` using the :class:`DisconnectHandler`. """ - def decorator(func): + def decorator(func: callable) -> Handler: handler = pyrogram.DisconnectHandler(func) if self is not None: diff --git a/pyrogram/client/methods/decorators/on_message.py b/pyrogram/client/methods/decorators/on_message.py index ec0e11e8..68ed1fab 100644 --- a/pyrogram/client/methods/decorators/on_message.py +++ b/pyrogram/client/methods/decorators/on_message.py @@ -24,7 +24,7 @@ from ...ext import BaseClient class OnMessage(BaseClient): def on_message(self=None, filters=None, - group: int = 0): + group: int = 0) -> callable: """Use this decorator to automatically register a function for handling messages. This does the same thing as :meth:`add_handler` using the :class:`MessageHandler`. diff --git a/pyrogram/client/methods/decorators/on_raw_update.py b/pyrogram/client/methods/decorators/on_raw_update.py index 8b2723df..ce2584d5 100644 --- a/pyrogram/client/methods/decorators/on_raw_update.py +++ b/pyrogram/client/methods/decorators/on_raw_update.py @@ -16,13 +16,16 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Tuple + import pyrogram +from pyrogram.client.handlers.handler import Handler from ...ext import BaseClient class OnRawUpdate(BaseClient): def on_raw_update(self=None, - group: int = 0): + group: int = 0) -> callable: """Use this decorator to automatically register a function for handling raw updates. This does the same thing as :meth:`add_handler` using the :class:`RawUpdateHandler`. @@ -39,7 +42,7 @@ class OnRawUpdate(BaseClient): The group identifier, defaults to 0. """ - def decorator(func): + def decorator(func: callable) -> Tuple[Handler, int]: if isinstance(func, tuple): func = func[0].callback diff --git a/pyrogram/client/methods/decorators/on_user_status.py b/pyrogram/client/methods/decorators/on_user_status.py index 6ae47a95..c552e706 100644 --- a/pyrogram/client/methods/decorators/on_user_status.py +++ b/pyrogram/client/methods/decorators/on_user_status.py @@ -16,15 +16,18 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Tuple + import pyrogram from pyrogram.client.filters.filter import Filter +from pyrogram.client.handlers.handler import Handler from ...ext import BaseClient class OnUserStatus(BaseClient): def on_user_status(self=None, filters=None, - group: int = 0): + group: int = 0) -> callable: """Use this decorator to automatically register a function for handling user status updates. This does the same thing as :meth:`add_handler` using the :class:`UserStatusHandler`. @@ -44,7 +47,7 @@ class OnUserStatus(BaseClient): The group identifier, defaults to 0. """ - def decorator(func): + def decorator(func: callable) -> Tuple[Handler, int]: if isinstance(func, tuple): func = func[0].callback diff --git a/pyrogram/client/methods/messages/delete_messages.py b/pyrogram/client/methods/messages/delete_messages.py index 6aaf710a..030a1663 100644 --- a/pyrogram/client/methods/messages/delete_messages.py +++ b/pyrogram/client/methods/messages/delete_messages.py @@ -26,7 +26,7 @@ class DeleteMessages(BaseClient): def delete_messages(self, chat_id: Union[int, str], message_ids: Iterable[int], - revoke: bool = True): + revoke: bool = True) -> bool: """Use this method to delete messages, including service messages, with the following limitations: - A message can only be deleted if it was sent less than 48 hours ago. diff --git a/pyrogram/client/methods/messages/edit_message_caption.py b/pyrogram/client/methods/messages/edit_message_caption.py index 938e7af5..7709a3d8 100644 --- a/pyrogram/client/methods/messages/edit_message_caption.py +++ b/pyrogram/client/methods/messages/edit_message_caption.py @@ -29,7 +29,7 @@ class EditMessageCaption(BaseClient): message_id: int, caption: str, parse_mode: str = "", - reply_markup: "pyrogram.InlineKeyboardMarkup" = None): + reply_markup: "pyrogram.InlineKeyboardMarkup" = None) -> "pyrogram.Message": """Use this method to edit captions of messages. Args: diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index bdfbf353..50fd1f48 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -38,7 +38,7 @@ class EditMessageMedia(BaseClient): chat_id: Union[int, str], message_id: int, media: InputMedia, - reply_markup: "pyrogram.InlineKeyboardMarkup" = None): + reply_markup: "pyrogram.InlineKeyboardMarkup" = None) -> "pyrogram.Message": """Use this method to edit audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, diff --git a/pyrogram/client/methods/messages/edit_message_reply_markup.py b/pyrogram/client/methods/messages/edit_message_reply_markup.py index 31d8f0b7..f46dd2f4 100644 --- a/pyrogram/client/methods/messages/edit_message_reply_markup.py +++ b/pyrogram/client/methods/messages/edit_message_reply_markup.py @@ -27,7 +27,7 @@ class EditMessageReplyMarkup(BaseClient): def edit_message_reply_markup(self, chat_id: Union[int, str], message_id: int, - reply_markup: "pyrogram.InlineKeyboardMarkup" = None): + reply_markup: "pyrogram.InlineKeyboardMarkup" = None) -> "pyrogram.Message": """Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). Args: diff --git a/pyrogram/client/methods/messages/edit_message_text.py b/pyrogram/client/methods/messages/edit_message_text.py index 688c7ce2..173caa93 100644 --- a/pyrogram/client/methods/messages/edit_message_text.py +++ b/pyrogram/client/methods/messages/edit_message_text.py @@ -30,7 +30,7 @@ class EditMessageText(BaseClient): text: str, parse_mode: str = "", disable_web_page_preview: bool = None, - reply_markup: "pyrogram.InlineKeyboardMarkup" = None): + reply_markup: "pyrogram.InlineKeyboardMarkup" = None) -> "pyrogram.Message": """Use this method to edit text messages. Args: diff --git a/pyrogram/client/methods/messages/forward_messages.py b/pyrogram/client/methods/messages/forward_messages.py index cafa468b..f8379c0c 100644 --- a/pyrogram/client/methods/messages/forward_messages.py +++ b/pyrogram/client/methods/messages/forward_messages.py @@ -28,7 +28,7 @@ class ForwardMessages(BaseClient): chat_id: Union[int, str], from_chat_id: Union[int, str], message_ids: Iterable[int], - disable_notification: bool = None): + disable_notification: bool = None) -> "pyrogram.Messages": """Use this method to forward messages of any kind. Args: @@ -51,7 +51,7 @@ class ForwardMessages(BaseClient): Users will receive a notification with no sound. Returns: - On success and in case *message_ids* was a list, the returned value will be a list of the forwarded + On success and in case *message_ids* was an iterable, the returned value will be a list of the forwarded :obj:`Messages ` even if a list contains just one element, otherwise if *message_ids* was an integer, the single forwarded :obj:`Message ` is returned. @@ -86,4 +86,8 @@ class ForwardMessages(BaseClient): ) ) - return messages if is_iterable else messages[0] + return pyrogram.Messages( + client=self, + total_count=len(messages), + messages=messages + ) if is_iterable else messages[0] diff --git a/pyrogram/client/methods/messages/get_messages.py b/pyrogram/client/methods/messages/get_messages.py index 9f67d9a0..da2f6578 100644 --- a/pyrogram/client/methods/messages/get_messages.py +++ b/pyrogram/client/methods/messages/get_messages.py @@ -28,7 +28,7 @@ class GetMessages(BaseClient): chat_id: Union[int, str], message_ids: Union[int, Iterable[int]] = None, reply_to_message_ids: Union[int, Iterable[int]] = None, - replies: int = 1): + replies: int = 1) -> "pyrogram.Messages": """Use this method to get one or more messages that belong to a specific chat. You can retrieve up to 200 messages at once. diff --git a/pyrogram/client/methods/messages/send_animation.py b/pyrogram/client/methods/messages/send_animation.py index 8e240f5b..7b1467f2 100644 --- a/pyrogram/client/methods/messages/send_animation.py +++ b/pyrogram/client/methods/messages/send_animation.py @@ -45,7 +45,7 @@ class SendAnimation(BaseClient): "pyrogram.ReplyKeyboardRemove", "pyrogram.ForceReply"] = None, progress: callable = None, - progress_args: tuple = ()): + progress_args: tuple = ()) -> "pyrogram.Message": """Use this method to send animation files (animation or H.264/MPEG-4 AVC video without sound). Args: diff --git a/pyrogram/client/methods/messages/send_audio.py b/pyrogram/client/methods/messages/send_audio.py index 405d0561..685e2a2b 100644 --- a/pyrogram/client/methods/messages/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -45,7 +45,7 @@ class SendAudio(BaseClient): "pyrogram.ReplyKeyboardRemove", "pyrogram.ForceReply"] = None, progress: callable = None, - progress_args: tuple = ()): + progress_args: tuple = ()) -> "pyrogram.Message": """Use this method to send audio files. For sending voice messages, use the :obj:`send_voice()` method instead. diff --git a/pyrogram/client/methods/messages/send_contact.py b/pyrogram/client/methods/messages/send_contact.py index d7f93743..5312f0ac 100644 --- a/pyrogram/client/methods/messages/send_contact.py +++ b/pyrogram/client/methods/messages/send_contact.py @@ -35,7 +35,7 @@ class SendContact(BaseClient): reply_markup: Union["pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", "pyrogram.ReplyKeyboardRemove", - "pyrogram.ForceReply"] = None): + "pyrogram.ForceReply"] = None) -> "pyrogram.Message": """Use this method to send phone contacts. Args: diff --git a/pyrogram/client/methods/messages/send_document.py b/pyrogram/client/methods/messages/send_document.py index d7bb62d1..da61aaea 100644 --- a/pyrogram/client/methods/messages/send_document.py +++ b/pyrogram/client/methods/messages/send_document.py @@ -42,7 +42,7 @@ class SendDocument(BaseClient): "pyrogram.ReplyKeyboardRemove", "pyrogram.ForceReply"] = None, progress: callable = None, - progress_args: tuple = ()): + progress_args: tuple = ()) -> "pyrogram.Message": """Use this method to send general files. Args: diff --git a/pyrogram/client/methods/messages/send_location.py b/pyrogram/client/methods/messages/send_location.py index 0efdb1df..dbd04e7a 100644 --- a/pyrogram/client/methods/messages/send_location.py +++ b/pyrogram/client/methods/messages/send_location.py @@ -33,7 +33,7 @@ class SendLocation(BaseClient): reply_markup: Union["pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", "pyrogram.ReplyKeyboardRemove", - "pyrogram.ForceReply"] = None): + "pyrogram.ForceReply"] = None) -> "pyrogram.Message": """Use this method to send points on the map. Args: diff --git a/pyrogram/client/methods/messages/send_message.py b/pyrogram/client/methods/messages/send_message.py index a04a67f2..982ce1c7 100644 --- a/pyrogram/client/methods/messages/send_message.py +++ b/pyrogram/client/methods/messages/send_message.py @@ -34,7 +34,7 @@ class SendMessage(BaseClient): reply_markup: Union["pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", "pyrogram.ReplyKeyboardRemove", - "pyrogram.ForceReply"] = None): + "pyrogram.ForceReply"] = None) -> "pyrogram.Message": """Use this method to send text messages. Args: diff --git a/pyrogram/client/methods/messages/send_photo.py b/pyrogram/client/methods/messages/send_photo.py index 5b7b3268..00d06ea1 100644 --- a/pyrogram/client/methods/messages/send_photo.py +++ b/pyrogram/client/methods/messages/send_photo.py @@ -41,7 +41,7 @@ class SendPhoto(BaseClient): "pyrogram.ReplyKeyboardRemove", "pyrogram.ForceReply"] = None, progress: callable = None, - progress_args: tuple = ()): + progress_args: tuple = ()) -> "pyrogram.Message": """Use this method to send photos. Args: diff --git a/pyrogram/client/methods/messages/send_sticker.py b/pyrogram/client/methods/messages/send_sticker.py index 550bcddb..045e1b21 100644 --- a/pyrogram/client/methods/messages/send_sticker.py +++ b/pyrogram/client/methods/messages/send_sticker.py @@ -38,7 +38,7 @@ class SendSticker(BaseClient): "pyrogram.ReplyKeyboardRemove", "pyrogram.ForceReply"] = None, progress: callable = None, - progress_args: tuple = ()): + progress_args: tuple = ()) -> "pyrogram.Message": """Use this method to send .webp stickers. Args: diff --git a/pyrogram/client/methods/messages/send_venue.py b/pyrogram/client/methods/messages/send_venue.py index 35d725d1..fca07898 100644 --- a/pyrogram/client/methods/messages/send_venue.py +++ b/pyrogram/client/methods/messages/send_venue.py @@ -37,7 +37,7 @@ class SendVenue(BaseClient): reply_markup: Union["pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", "pyrogram.ReplyKeyboardRemove", - "pyrogram.ForceReply"] = None): + "pyrogram.ForceReply"] = None) -> "pyrogram.Message": """Use this method to send information about a venue. Args: diff --git a/pyrogram/client/methods/messages/send_video.py b/pyrogram/client/methods/messages/send_video.py index c6936cff..fa0a51a6 100644 --- a/pyrogram/client/methods/messages/send_video.py +++ b/pyrogram/client/methods/messages/send_video.py @@ -46,7 +46,7 @@ class SendVideo(BaseClient): "pyrogram.ReplyKeyboardRemove", "pyrogram.ForceReply"] = None, progress: callable = None, - progress_args: tuple = ()): + progress_args: tuple = ()) -> "pyrogram.Message": """Use this method to send video files. Args: diff --git a/pyrogram/client/methods/messages/send_video_note.py b/pyrogram/client/methods/messages/send_video_note.py index 75345607..dd64c14a 100644 --- a/pyrogram/client/methods/messages/send_video_note.py +++ b/pyrogram/client/methods/messages/send_video_note.py @@ -42,7 +42,7 @@ class SendVideoNote(BaseClient): "pyrogram.ReplyKeyboardRemove", "pyrogram.ForceReply"] = None, progress: callable = None, - progress_args: tuple = ()): + progress_args: tuple = ()) -> "pyrogram.Message": """Use this method to send video messages. Args: diff --git a/pyrogram/client/methods/messages/send_voice.py b/pyrogram/client/methods/messages/send_voice.py index 52cbc833..27621fa0 100644 --- a/pyrogram/client/methods/messages/send_voice.py +++ b/pyrogram/client/methods/messages/send_voice.py @@ -42,7 +42,7 @@ class SendVoice(BaseClient): "pyrogram.ReplyKeyboardRemove", "pyrogram.ForceReply"] = None, progress: callable = None, - progress_args: tuple = ()): + progress_args: tuple = ()) -> "pyrogram.Message": """Use this method to send audio files. Args: diff --git a/pyrogram/client/methods/password/change_cloud_password.py b/pyrogram/client/methods/password/change_cloud_password.py index 600f58fa..d7d0e1fa 100644 --- a/pyrogram/client/methods/password/change_cloud_password.py +++ b/pyrogram/client/methods/password/change_cloud_password.py @@ -27,7 +27,7 @@ class ChangeCloudPassword(BaseClient): def change_cloud_password(self, current_password: str, new_password: str, - new_hint: str = ""): + new_hint: str = "") -> bool: """Use this method to change your Two-Step Verification password (Cloud Password) with a new one. Args: diff --git a/pyrogram/client/methods/password/enable_cloud_password.py b/pyrogram/client/methods/password/enable_cloud_password.py index 77c731dd..4eb8df6a 100644 --- a/pyrogram/client/methods/password/enable_cloud_password.py +++ b/pyrogram/client/methods/password/enable_cloud_password.py @@ -27,7 +27,7 @@ class EnableCloudPassword(BaseClient): def enable_cloud_password(self, password: str, hint: str = "", - email: str = ""): + email: str = "") -> bool: """Use this method to enable the Two-Step Verification security feature (Cloud Password) on your account. This password will be asked when you log in on a new device in addition to the SMS code. diff --git a/pyrogram/client/methods/password/remove_cloud_password.py b/pyrogram/client/methods/password/remove_cloud_password.py index c82436b7..3dab720d 100644 --- a/pyrogram/client/methods/password/remove_cloud_password.py +++ b/pyrogram/client/methods/password/remove_cloud_password.py @@ -24,7 +24,7 @@ from ...ext import BaseClient class RemoveCloudPassword(BaseClient): def remove_cloud_password(self, - password: str): + password: str) -> bool: """Use this method to turn off the Two-Step Verification security feature (Cloud Password) on your account. Args: diff --git a/pyrogram/client/methods/users/delete_user_profile_photos.py b/pyrogram/client/methods/users/delete_user_profile_photos.py index 4f3c5fde..764c3f3e 100644 --- a/pyrogram/client/methods/users/delete_user_profile_photos.py +++ b/pyrogram/client/methods/users/delete_user_profile_photos.py @@ -26,7 +26,7 @@ from ...ext import BaseClient class DeleteUserProfilePhotos(BaseClient): def delete_user_profile_photos(self, - id: Union[str, List[str]]): + id: Union[str, List[str]]) -> bool: """Use this method to delete your own profile photos Args: diff --git a/pyrogram/client/methods/users/get_me.py b/pyrogram/client/methods/users/get_me.py index 9072a909..3f3e85c3 100644 --- a/pyrogram/client/methods/users/get_me.py +++ b/pyrogram/client/methods/users/get_me.py @@ -22,7 +22,7 @@ from ...ext import BaseClient class GetMe(BaseClient): - def get_me(self): + def get_me(self) -> pyrogram.User: """A simple method for testing your authorization. Requires no parameters. Returns: diff --git a/pyrogram/client/methods/users/get_user_profile_photos.py b/pyrogram/client/methods/users/get_user_profile_photos.py index 86ecb74d..c097aced 100644 --- a/pyrogram/client/methods/users/get_user_profile_photos.py +++ b/pyrogram/client/methods/users/get_user_profile_photos.py @@ -27,7 +27,7 @@ class GetUserProfilePhotos(BaseClient): def get_user_profile_photos(self, user_id: Union[int, str], offset: int = 0, - limit: int = 100): + limit: int = 100) -> pyrogram.UserProfilePhotos: """Use this method to get a list of profile pictures for a user. Args: diff --git a/pyrogram/client/methods/users/get_users.py b/pyrogram/client/methods/users/get_users.py index 075814ca..3ee1bc61 100644 --- a/pyrogram/client/methods/users/get_users.py +++ b/pyrogram/client/methods/users/get_users.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Iterable, Union +from typing import Iterable, Union, List import pyrogram from pyrogram.api import functions @@ -25,7 +25,7 @@ from ...ext import BaseClient class GetUsers(BaseClient): def get_users(self, - user_ids: Iterable[Union[int, str]]): + user_ids: Iterable[Union[int, str]]) -> Union[pyrogram.User or List[pyrogram.User]]: """Use this method to get information about a user. You can retrieve up to 200 users at once. @@ -36,9 +36,9 @@ class GetUsers(BaseClient): Iterators and Generators are also accepted. Returns: - On success and in case *user_ids* was a list, the returned value will be a list of the requested + On success and in case *user_ids* was an iterable, the returned value will be a list of the requested :obj:`Users ` even if a list contains just one element, otherwise if - *user_ids* was an integer, the single requested :obj:`User` is returned. + *user_ids* was an integer or string, the single requested :obj:`User` is returned. Raises: :class:`Error ` in case of a Telegram RPC error. diff --git a/pyrogram/client/methods/users/set_user_profile_photo.py b/pyrogram/client/methods/users/set_user_profile_photo.py index 68e174d6..f2a2c302 100644 --- a/pyrogram/client/methods/users/set_user_profile_photo.py +++ b/pyrogram/client/methods/users/set_user_profile_photo.py @@ -22,7 +22,7 @@ from ...ext import BaseClient class SetUserProfilePhoto(BaseClient): def set_user_profile_photo(self, - photo: str): + photo: str) -> bool: """Use this method to set a new profile photo. This method only works for Users. diff --git a/pyrogram/client/methods/utilities/download_media.py b/pyrogram/client/methods/utilities/download_media.py index 8c609d98..33d72f82 100644 --- a/pyrogram/client/methods/utilities/download_media.py +++ b/pyrogram/client/methods/utilities/download_media.py @@ -29,7 +29,7 @@ class DownloadMedia(BaseClient): file_name: str = "", block: bool = True, progress: callable = None, - progress_args: tuple = ()): + progress_args: tuple = ()) -> Union[str, None]: """Use this method to download the media from a Message. Args: diff --git a/pyrogram/client/types/user_and_chats/chat_member.py b/pyrogram/client/types/user_and_chats/chat_member.py index b778d4d8..fa43f526 100644 --- a/pyrogram/client/types/user_and_chats/chat_member.py +++ b/pyrogram/client/types/user_and_chats/chat_member.py @@ -121,6 +121,8 @@ class ChatMember(PyrogramType): @staticmethod def _parse(client, member, user) -> "ChatMember": + user = pyrogram.User._parse(client, user) + if isinstance(member, (types.ChannelParticipant, types.ChannelParticipantSelf, types.ChatParticipant)): return ChatMember(user=user, status="member", client=client)