From b593463bd7819b18a36175e590243786dccc637d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Dec 2018 14:50:23 +0100 Subject: [PATCH] Type hint all the remaining method parameters --- .../methods/bots/get_inline_bot_results.py | 4 ++- .../methods/bots/request_callback_answer.py | 4 ++- .../methods/bots/send_inline_bot_result.py | 4 ++- .../client/methods/chats/delete_chat_photo.py | 5 ++- .../methods/chats/export_chat_invite_link.py | 5 ++- pyrogram/client/methods/chats/get_chat.py | 7 ++-- .../client/methods/chats/get_chat_member.py | 10 +++--- .../client/methods/chats/get_chat_members.py | 8 +++-- .../methods/chats/get_chat_members_count.py | 5 ++- pyrogram/client/methods/chats/get_dialogs.py | 4 +-- pyrogram/client/methods/chats/join_chat.py | 3 +- .../client/methods/chats/kick_chat_member.py | 8 +++-- pyrogram/client/methods/chats/leave_chat.py | 6 +++- .../client/methods/chats/pin_chat_message.py | 7 +++- .../methods/chats/promote_chat_member.py | 6 ++-- .../methods/chats/restrict_chat_member.py | 6 ++-- .../methods/chats/set_chat_description.py | 6 +++- .../client/methods/chats/set_chat_photo.py | 5 ++- .../client/methods/chats/set_chat_title.py | 6 +++- .../client/methods/chats/unban_chat_member.py | 6 ++-- .../methods/chats/unpin_chat_message.py | 5 ++- .../client/methods/contacts/add_contacts.py | 10 ++++-- .../methods/contacts/delete_contacts.py | 7 ++-- .../methods/decorators/on_callback_query.py | 4 ++- .../methods/decorators/on_deleted_messages.py | 4 ++- .../client/methods/decorators/on_message.py | 4 ++- .../methods/decorators/on_raw_update.py | 3 +- .../methods/decorators/on_user_status.py | 4 ++- .../methods/messages/delete_messages.py | 6 ++-- .../methods/messages/edit_message_caption.py | 9 ++--- .../methods/messages/edit_message_media.py | 10 +++--- .../messages/edit_message_reply_markup.py | 8 +++-- .../methods/messages/edit_message_text.py | 8 +++-- .../methods/messages/forward_messages.py | 10 +++--- .../client/methods/messages/get_history.py | 6 ++-- .../client/methods/messages/get_messages.py | 10 +++--- .../client/methods/messages/send_animation.py | 10 ++++-- .../client/methods/messages/send_audio.py | 10 ++++-- .../methods/messages/send_chat_action.py | 6 ++-- .../client/methods/messages/send_contact.py | 11 +++++-- .../client/methods/messages/send_document.py | 10 ++++-- .../client/methods/messages/send_location.py | 11 +++++-- .../methods/messages/send_media_group.py | 11 ++++--- .../client/methods/messages/send_message.py | 11 +++++-- .../client/methods/messages/send_photo.py | 10 ++++-- .../client/methods/messages/send_sticker.py | 10 ++++-- .../client/methods/messages/send_venue.py | 11 +++++-- .../client/methods/messages/send_video.py | 10 ++++-- .../methods/messages/send_video_note.py | 10 ++++-- .../client/methods/messages/send_voice.py | 10 ++++-- .../methods/password/change_cloud_password.py | 5 ++- .../methods/password/enable_cloud_password.py | 5 ++- .../methods/password/remove_cloud_password.py | 3 +- .../users/delete_user_profile_photos.py | 4 ++- pyrogram/client/methods/users/get_me.py | 2 +- .../methods/users/get_user_profile_photos.py | 6 ++-- pyrogram/client/methods/users/get_users.py | 7 ++-- .../methods/users/set_user_profile_photo.py | 3 +- .../methods/utilities/download_media.py | 33 ++++++++++--------- .../types/messages_and_media/message.py | 2 +- 60 files changed, 295 insertions(+), 139 deletions(-) diff --git a/pyrogram/client/methods/bots/get_inline_bot_results.py b/pyrogram/client/methods/bots/get_inline_bot_results.py index cb931d49..a5b9ae9f 100644 --- a/pyrogram/client/methods/bots/get_inline_bot_results.py +++ b/pyrogram/client/methods/bots/get_inline_bot_results.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions, types from pyrogram.api.errors import UnknownError from pyrogram.client.ext import BaseClient @@ -23,7 +25,7 @@ from pyrogram.client.ext import BaseClient class GetInlineBotResults(BaseClient): def get_inline_bot_results(self, - bot: int or str, + bot: Union[int, str], query: str, offset: str = "", latitude: float = None, diff --git a/pyrogram/client/methods/bots/request_callback_answer.py b/pyrogram/client/methods/bots/request_callback_answer.py index 470ad15a..0cb6a1dd 100644 --- a/pyrogram/client/methods/bots/request_callback_answer.py +++ b/pyrogram/client/methods/bots/request_callback_answer.py @@ -16,13 +16,15 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions from pyrogram.client.ext import BaseClient class RequestCallbackAnswer(BaseClient): def request_callback_answer(self, - chat_id: int or str, + chat_id: Union[int, str], message_id: int, callback_data: bytes): """Use this method to request a callback answer from bots. This is the equivalent of clicking an diff --git a/pyrogram/client/methods/bots/send_inline_bot_result.py b/pyrogram/client/methods/bots/send_inline_bot_result.py index 97ea2a4a..23d36cba 100644 --- a/pyrogram/client/methods/bots/send_inline_bot_result.py +++ b/pyrogram/client/methods/bots/send_inline_bot_result.py @@ -16,13 +16,15 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions from pyrogram.client.ext import BaseClient class SendInlineBotResult(BaseClient): def send_inline_bot_result(self, - chat_id: int or str, + chat_id: Union[int, str], query_id: int, result_id: str, disable_notification: bool = None, diff --git a/pyrogram/client/methods/chats/delete_chat_photo.py b/pyrogram/client/methods/chats/delete_chat_photo.py index 5a1fe74e..d4658e4d 100644 --- a/pyrogram/client/methods/chats/delete_chat_photo.py +++ b/pyrogram/client/methods/chats/delete_chat_photo.py @@ -16,12 +16,15 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions, types from ...ext import BaseClient class DeleteChatPhoto(BaseClient): - def delete_chat_photo(self, chat_id: int or str): + def delete_chat_photo(self, + chat_id: Union[int, str]): """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 4972493b..8f068586 100644 --- a/pyrogram/client/methods/chats/export_chat_invite_link.py +++ b/pyrogram/client/methods/chats/export_chat_invite_link.py @@ -16,12 +16,15 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions, types from ...ext import BaseClient class ExportChatInviteLink(BaseClient): - def export_chat_invite_link(self, chat_id: int or str): + def export_chat_invite_link(self, + chat_id: Union[int, 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 7c191bf3..24651d37 100644 --- a/pyrogram/client/methods/chats/get_chat.py +++ b/pyrogram/client/methods/chats/get_chat.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 Union + import pyrogram from pyrogram.api import functions, types from ...ext import BaseClient class GetChat(BaseClient): - def get_chat(self, chat_id: int or str): + def get_chat(self, + chat_id: Union[int, str]): """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.) @@ -45,4 +48,4 @@ class GetChat(BaseClient): else: r = self.send(functions.messages.GetFullChat(peer.chat_id)) - return pyrogram.Chat.parse_full(self, r) + return pyrogram.Chat._parse_full(self, r) diff --git a/pyrogram/client/methods/chats/get_chat_member.py b/pyrogram/client/methods/chats/get_chat_member.py index b304be17..7708f6fc 100644 --- a/pyrogram/client/methods/chats/get_chat_member.py +++ b/pyrogram/client/methods/chats/get_chat_member.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.api import functions, types, errors from ...ext import BaseClient @@ -23,8 +25,8 @@ from ...ext import BaseClient class GetChatMember(BaseClient): def get_chat_member(self, - chat_id: int or str, - user_id: int or str): + chat_id: Union[int, str], + user_id: Union[int, str]): """Use this method to get information about one member of a chat. Args: @@ -52,7 +54,7 @@ class GetChatMember(BaseClient): ) ) - for member in pyrogram.ChatMembers.parse(self, full_chat).chat_members: + for member in pyrogram.ChatMembers._parse(self, full_chat).chat_members: if member.user.id == user_id.user_id: return member else: @@ -65,7 +67,7 @@ class GetChatMember(BaseClient): ) ) - return pyrogram.ChatMembers.parse( + return pyrogram.ChatMembers._parse( self, types.channels.ChannelParticipants( count=1, diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index 71728676..031ea46b 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.api import functions, types from ...ext import BaseClient @@ -32,7 +34,7 @@ class Filters: class GetChatMembers(BaseClient): def get_chat_members(self, - chat_id: int or str, + chat_id: Union[int, str], offset: int = 0, limit: int = 200, query: str = "", @@ -84,7 +86,7 @@ class GetChatMembers(BaseClient): peer = self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChat): - return pyrogram.ChatMembers.parse( + return pyrogram.ChatMembers._parse( self, self.send( functions.messages.GetFullChat( @@ -110,7 +112,7 @@ class GetChatMembers(BaseClient): else: raise ValueError("Invalid filter \"{}\"".format(filter)) - return pyrogram.ChatMembers.parse( + return pyrogram.ChatMembers._parse( self, self.send( functions.channels.GetParticipants( diff --git a/pyrogram/client/methods/chats/get_chat_members_count.py b/pyrogram/client/methods/chats/get_chat_members_count.py index ec5aaae0..01bbd835 100644 --- a/pyrogram/client/methods/chats/get_chat_members_count.py +++ b/pyrogram/client/methods/chats/get_chat_members_count.py @@ -16,12 +16,15 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions, types from ...ext import BaseClient class GetChatMembersCount(BaseClient): - def get_chat_members_count(self, chat_id: int or str): + def get_chat_members_count(self, + chat_id: Union[int, str]): """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 f8bed7c8..87cd5be2 100644 --- a/pyrogram/client/methods/chats/get_dialogs.py +++ b/pyrogram/client/methods/chats/get_dialogs.py @@ -23,7 +23,7 @@ from ...ext import BaseClient class GetDialogs(BaseClient): def get_dialogs(self, - offset_dialog=None, + offset_dialog: "pyrogram.Dialog" = None, limit: int = 100, pinned_only: bool = False): """Use this method to get the user's dialogs @@ -64,4 +64,4 @@ class GetDialogs(BaseClient): ) ) - return pyrogram.Dialogs.parse(self, r) + return pyrogram.Dialogs._parse(self, r) diff --git a/pyrogram/client/methods/chats/join_chat.py b/pyrogram/client/methods/chats/join_chat.py index f5e3953c..2f14c617 100644 --- a/pyrogram/client/methods/chats/join_chat.py +++ b/pyrogram/client/methods/chats/join_chat.py @@ -21,7 +21,8 @@ from ...ext import BaseClient class JoinChat(BaseClient): - def join_chat(self, chat_id: str): + def join_chat(self, + chat_id: str): """Use this method to join a group chat or channel. Args: diff --git a/pyrogram/client/methods/chats/kick_chat_member.py b/pyrogram/client/methods/chats/kick_chat_member.py index 292fdfd6..a7459110 100644 --- a/pyrogram/client/methods/chats/kick_chat_member.py +++ b/pyrogram/client/methods/chats/kick_chat_member.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.api import functions, types from ...ext import BaseClient @@ -23,8 +25,8 @@ from ...ext import BaseClient class KickChatMember(BaseClient): def kick_chat_member(self, - chat_id: int or str, - user_id: int or str, + chat_id: Union[int, str], + user_id: Union[int, str], until_date: int = 0): """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 @@ -86,7 +88,7 @@ class KickChatMember(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/chats/leave_chat.py b/pyrogram/client/methods/chats/leave_chat.py index 8f070b82..e0ac3bb6 100644 --- a/pyrogram/client/methods/chats/leave_chat.py +++ b/pyrogram/client/methods/chats/leave_chat.py @@ -16,12 +16,16 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions, types from ...ext import BaseClient class LeaveChat(BaseClient): - def leave_chat(self, chat_id: int or str, delete: bool = False): + def leave_chat(self, + chat_id: Union[int, str], + delete: bool = False): """Use this method to leave a group chat or channel. Args: diff --git a/pyrogram/client/methods/chats/pin_chat_message.py b/pyrogram/client/methods/chats/pin_chat_message.py index de7e69d4..1ef07d34 100644 --- a/pyrogram/client/methods/chats/pin_chat_message.py +++ b/pyrogram/client/methods/chats/pin_chat_message.py @@ -16,12 +16,17 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions, types from ...ext import BaseClient class PinChatMessage(BaseClient): - def pin_chat_message(self, chat_id: int or str, message_id: int, disable_notification: bool = None): + def pin_chat_message(self, + chat_id: Union[int, str], + message_id: int, + disable_notification: bool = None): """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 9db7709b..d22a8ea7 100644 --- a/pyrogram/client/methods/chats/promote_chat_member.py +++ b/pyrogram/client/methods/chats/promote_chat_member.py @@ -16,14 +16,16 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions, types from ...ext import BaseClient class PromoteChatMember(BaseClient): def promote_chat_member(self, - chat_id: int or str, - user_id: int or str, + chat_id: Union[int, str], + user_id: Union[int, str], can_change_info: bool = True, can_post_messages: bool = False, can_edit_messages: bool = False, diff --git a/pyrogram/client/methods/chats/restrict_chat_member.py b/pyrogram/client/methods/chats/restrict_chat_member.py index 35db5e59..c772d100 100644 --- a/pyrogram/client/methods/chats/restrict_chat_member.py +++ b/pyrogram/client/methods/chats/restrict_chat_member.py @@ -16,14 +16,16 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions, types from ...ext import BaseClient class RestrictChatMember(BaseClient): def restrict_chat_member(self, - chat_id: int or str, - user_id: int or str, + chat_id: Union[int, str], + user_id: Union[int, str], until_date: int = 0, can_send_messages: bool = False, can_send_media_messages: bool = False, diff --git a/pyrogram/client/methods/chats/set_chat_description.py b/pyrogram/client/methods/chats/set_chat_description.py index 5f5ead7f..1606fe7e 100644 --- a/pyrogram/client/methods/chats/set_chat_description.py +++ b/pyrogram/client/methods/chats/set_chat_description.py @@ -16,12 +16,16 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions, types from ...ext import BaseClient class SetChatDescription(BaseClient): - def set_chat_description(self, chat_id: int or str, description: str): + def set_chat_description(self, + chat_id: Union[int, str], + description: str): """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 51045a8a..ed058000 100644 --- a/pyrogram/client/methods/chats/set_chat_photo.py +++ b/pyrogram/client/methods/chats/set_chat_photo.py @@ -19,13 +19,16 @@ import os from base64 import b64decode from struct import unpack +from typing import Union from pyrogram.api import functions, types from ...ext import BaseClient class SetChatPhoto(BaseClient): - def set_chat_photo(self, chat_id: int or str, photo: str): + def set_chat_photo(self, + chat_id: Union[int, str], + photo: str): """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 c7176c82..58d4179c 100644 --- a/pyrogram/client/methods/chats/set_chat_title.py +++ b/pyrogram/client/methods/chats/set_chat_title.py @@ -16,12 +16,16 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions, types from ...ext import BaseClient class SetChatTitle(BaseClient): - def set_chat_title(self, chat_id: int or str, title: str): + def set_chat_title(self, + chat_id: Union[int, str], + title: str): """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 c8b20131..428e6fe8 100644 --- a/pyrogram/client/methods/chats/unban_chat_member.py +++ b/pyrogram/client/methods/chats/unban_chat_member.py @@ -16,14 +16,16 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions, types from ...ext import BaseClient class UnbanChatMember(BaseClient): def unban_chat_member(self, - chat_id: int or str, - user_id: int or str): + chat_id: Union[int, str], + user_id: Union[int, str]): """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 9bbb1021..bd6a22f8 100644 --- a/pyrogram/client/methods/chats/unpin_chat_message.py +++ b/pyrogram/client/methods/chats/unpin_chat_message.py @@ -16,12 +16,15 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions, types from ...ext import BaseClient class UnpinChatMessage(BaseClient): - def unpin_chat_message(self, chat_id: int or str): + def unpin_chat_message(self, + chat_id: Union[int, str]): """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/contacts/add_contacts.py b/pyrogram/client/methods/contacts/add_contacts.py index 3a1dcc92..a5f06050 100644 --- a/pyrogram/client/methods/contacts/add_contacts.py +++ b/pyrogram/client/methods/contacts/add_contacts.py @@ -16,17 +16,21 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import List + +import pyrogram from pyrogram.api import functions from ...ext import BaseClient class AddContacts(BaseClient): - def add_contacts(self, contacts: list): + def add_contacts(self, + contacts: List["pyrogram.InputPhoneContact"]): """Use this method to add contacts to your Telegram address book. Args: - contacts (``list``): - A list of :obj:`InputPhoneContact ` + contacts (List of :obj:`InputPhoneContact `): + The contact list to be added Returns: On success, the added contacts are returned. diff --git a/pyrogram/client/methods/contacts/delete_contacts.py b/pyrogram/client/methods/contacts/delete_contacts.py index 74f08dd1..2c18c6d8 100644 --- a/pyrogram/client/methods/contacts/delete_contacts.py +++ b/pyrogram/client/methods/contacts/delete_contacts.py @@ -16,17 +16,20 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import List + from pyrogram.api import functions, types from pyrogram.api.errors import PeerIdInvalid from ...ext import BaseClient class DeleteContacts(BaseClient): - def delete_contacts(self, ids: list): + def delete_contacts(self, + ids: List[int]): """Use this method to delete contacts from your Telegram address book Args: - ids (``list``): + ids (List of ``int``): A list of unique identifiers for the target users. Can be an ID (int), a username (string) or phone number (string). diff --git a/pyrogram/client/methods/decorators/on_callback_query.py b/pyrogram/client/methods/decorators/on_callback_query.py index 51a6df2e..f34119e2 100644 --- a/pyrogram/client/methods/decorators/on_callback_query.py +++ b/pyrogram/client/methods/decorators/on_callback_query.py @@ -22,7 +22,9 @@ from ...ext import BaseClient class OnCallbackQuery(BaseClient): - def on_callback_query(self=None, filters=None, group: int = 0): + def on_callback_query(self=None, + filters=None, + group: int = 0): """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`. diff --git a/pyrogram/client/methods/decorators/on_deleted_messages.py b/pyrogram/client/methods/decorators/on_deleted_messages.py index c23b7594..406563f2 100644 --- a/pyrogram/client/methods/decorators/on_deleted_messages.py +++ b/pyrogram/client/methods/decorators/on_deleted_messages.py @@ -22,7 +22,9 @@ from ...ext import BaseClient class OnDeletedMessages(BaseClient): - def on_deleted_messages(self=None, filters=None, group: int = 0): + def on_deleted_messages(self=None, + filters=None, + group: int = 0): """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`. diff --git a/pyrogram/client/methods/decorators/on_message.py b/pyrogram/client/methods/decorators/on_message.py index a098cfa2..ec0e11e8 100644 --- a/pyrogram/client/methods/decorators/on_message.py +++ b/pyrogram/client/methods/decorators/on_message.py @@ -22,7 +22,9 @@ from ...ext import BaseClient class OnMessage(BaseClient): - def on_message(self=None, filters=None, group: int = 0): + def on_message(self=None, + filters=None, + group: int = 0): """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 52728e1c..8b2723df 100644 --- a/pyrogram/client/methods/decorators/on_raw_update.py +++ b/pyrogram/client/methods/decorators/on_raw_update.py @@ -21,7 +21,8 @@ from ...ext import BaseClient class OnRawUpdate(BaseClient): - def on_raw_update(self=None, group: int = 0): + def on_raw_update(self=None, + group: int = 0): """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`. diff --git a/pyrogram/client/methods/decorators/on_user_status.py b/pyrogram/client/methods/decorators/on_user_status.py index 2ca41e56..6ae47a95 100644 --- a/pyrogram/client/methods/decorators/on_user_status.py +++ b/pyrogram/client/methods/decorators/on_user_status.py @@ -22,7 +22,9 @@ from ...ext import BaseClient class OnUserStatus(BaseClient): - def on_user_status(self=None, filters=None, group: int = 0): + def on_user_status(self=None, + filters=None, + group: int = 0): """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`. diff --git a/pyrogram/client/methods/messages/delete_messages.py b/pyrogram/client/methods/messages/delete_messages.py index f824a4b6..6aaf710a 100644 --- a/pyrogram/client/methods/messages/delete_messages.py +++ b/pyrogram/client/methods/messages/delete_messages.py @@ -16,14 +16,16 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union, Iterable + from pyrogram.api import functions, types from pyrogram.client.ext import BaseClient class DeleteMessages(BaseClient): def delete_messages(self, - chat_id: int or str, - message_ids, + chat_id: Union[int, str], + message_ids: Iterable[int], revoke: bool = True): """Use this method to delete messages, including service messages, with the following limitations: diff --git a/pyrogram/client/methods/messages/edit_message_caption.py b/pyrogram/client/methods/messages/edit_message_caption.py index a79c21f4..938e7af5 100644 --- a/pyrogram/client/methods/messages/edit_message_caption.py +++ b/pyrogram/client/methods/messages/edit_message_caption.py @@ -16,19 +16,20 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -import pyrogram +from typing import Union +import pyrogram from pyrogram.api import functions, types from pyrogram.client.ext import BaseClient class EditMessageCaption(BaseClient): def edit_message_caption(self, - chat_id: int or str, + chat_id: Union[int, str], message_id: int, caption: str, parse_mode: str = "", - reply_markup=None): + reply_markup: "pyrogram.InlineKeyboardMarkup" = None): """Use this method to edit captions of messages. Args: @@ -70,7 +71,7 @@ class EditMessageCaption(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 5d06c31b..bdfbf353 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -20,6 +20,7 @@ import binascii import mimetypes import os import struct +from typing import Union import pyrogram from pyrogram.api import functions, types @@ -29,14 +30,15 @@ from pyrogram.client.types import ( InputMediaPhoto, InputMediaVideo, InputMediaAudio, InputMediaAnimation, InputMediaDocument ) +from pyrogram.client.types.input_media import InputMedia class EditMessageMedia(BaseClient): def edit_message_media(self, - chat_id: int or str, + chat_id: Union[int, str], message_id: int, - media, - reply_markup=None): + media: InputMedia, + reply_markup: "pyrogram.InlineKeyboardMarkup" = None): """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, @@ -334,7 +336,7 @@ class EditMessageMedia(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/edit_message_reply_markup.py b/pyrogram/client/methods/messages/edit_message_reply_markup.py index 3b301dcb..31d8f0b7 100644 --- a/pyrogram/client/methods/messages/edit_message_reply_markup.py +++ b/pyrogram/client/methods/messages/edit_message_reply_markup.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.api import functions, types from pyrogram.client.ext import BaseClient @@ -23,9 +25,9 @@ from pyrogram.client.ext import BaseClient class EditMessageReplyMarkup(BaseClient): def edit_message_reply_markup(self, - chat_id: int or str, + chat_id: Union[int, str], message_id: int, - reply_markup=None): + reply_markup: "pyrogram.InlineKeyboardMarkup" = None): """Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). Args: @@ -58,7 +60,7 @@ class EditMessageReplyMarkup(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/edit_message_text.py b/pyrogram/client/methods/messages/edit_message_text.py index 991ff049..688c7ce2 100644 --- a/pyrogram/client/methods/messages/edit_message_text.py +++ b/pyrogram/client/methods/messages/edit_message_text.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.api import functions, types from pyrogram.client.ext import BaseClient @@ -23,12 +25,12 @@ from pyrogram.client.ext import BaseClient class EditMessageText(BaseClient): def edit_message_text(self, - chat_id: int or str, + chat_id: Union[int, str], message_id: int, text: str, parse_mode: str = "", disable_web_page_preview: bool = None, - reply_markup=None): + reply_markup: "pyrogram.InlineKeyboardMarkup" = None): """Use this method to edit text messages. Args: @@ -74,7 +76,7 @@ class EditMessageText(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/forward_messages.py b/pyrogram/client/methods/messages/forward_messages.py index e2e10c93..cafa468b 100644 --- a/pyrogram/client/methods/messages/forward_messages.py +++ b/pyrogram/client/methods/messages/forward_messages.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union, Iterable + import pyrogram from pyrogram.api import functions, types from ...ext import BaseClient @@ -23,9 +25,9 @@ from ...ext import BaseClient class ForwardMessages(BaseClient): def forward_messages(self, - chat_id: int or str, - from_chat_id: int or str, - message_ids, + chat_id: Union[int, str], + from_chat_id: Union[int, str], + message_ids: Iterable[int], disable_notification: bool = None): """Use this method to forward messages of any kind. @@ -78,7 +80,7 @@ class ForwardMessages(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): messages.append( - pyrogram.Message.parse( + pyrogram.Message._parse( self, i.message, users, chats ) diff --git a/pyrogram/client/methods/messages/get_history.py b/pyrogram/client/methods/messages/get_history.py index bc272ce3..2a36d46c 100644 --- a/pyrogram/client/methods/messages/get_history.py +++ b/pyrogram/client/methods/messages/get_history.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.api import functions from ...ext import BaseClient @@ -23,7 +25,7 @@ from ...ext import BaseClient class GetHistory(BaseClient): def get_history(self, - chat_id: int or str, + chat_id: Union[int, str], offset: int = 0, limit: int = 100, offset_id: int = 0, @@ -59,7 +61,7 @@ class GetHistory(BaseClient): :class:`Error ` in case of a Telegram RPC error. """ - return pyrogram.Messages.parse( + return pyrogram.Messages._parse( self, self.send( functions.messages.GetHistory( diff --git a/pyrogram/client/methods/messages/get_messages.py b/pyrogram/client/methods/messages/get_messages.py index 2e3930ae..9f67d9a0 100644 --- a/pyrogram/client/methods/messages/get_messages.py +++ b/pyrogram/client/methods/messages/get_messages.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union, Iterable + import pyrogram from pyrogram.api import functions, types from ...ext import BaseClient @@ -23,9 +25,9 @@ from ...ext import BaseClient class GetMessages(BaseClient): def get_messages(self, - chat_id: int or str, - message_ids: int or list = None, - reply_to_message_ids: int or list = None, + chat_id: Union[int, str], + message_ids: Union[int, Iterable[int]] = None, + reply_to_message_ids: Union[int, Iterable[int]] = None, replies: int = 1): """Use this method to get one or more messages that belong to a specific chat. You can retrieve up to 200 messages at once. @@ -76,6 +78,6 @@ class GetMessages(BaseClient): else: rpc = functions.messages.GetMessages(id=ids) - messages = pyrogram.Messages.parse(self, self.send(rpc)) + messages = pyrogram.Messages._parse(self, self.send(rpc)) return messages if is_iterable else messages.messages[0] diff --git a/pyrogram/client/methods/messages/send_animation.py b/pyrogram/client/methods/messages/send_animation.py index c86fb867..8e240f5b 100644 --- a/pyrogram/client/methods/messages/send_animation.py +++ b/pyrogram/client/methods/messages/send_animation.py @@ -20,6 +20,7 @@ import binascii import mimetypes import os import struct +from typing import Union import pyrogram from pyrogram.api import functions, types @@ -29,7 +30,7 @@ from pyrogram.client.ext import BaseClient, utils class SendAnimation(BaseClient): def send_animation(self, - chat_id: int or str, + chat_id: Union[int, str], animation: str, caption: str = "", parse_mode: str = "", @@ -39,7 +40,10 @@ class SendAnimation(BaseClient): thumb: str = None, disable_notification: bool = None, reply_to_message_id: int = None, - reply_markup=None, + reply_markup: Union["pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply"] = None, progress: callable = None, progress_args: tuple = ()): """Use this method to send animation files (animation or H.264/MPEG-4 AVC video without sound). @@ -185,7 +189,7 @@ class SendAnimation(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_audio.py b/pyrogram/client/methods/messages/send_audio.py index 12c65dec..405d0561 100644 --- a/pyrogram/client/methods/messages/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -20,6 +20,7 @@ import binascii import mimetypes import os import struct +from typing import Union import pyrogram from pyrogram.api import functions, types @@ -29,7 +30,7 @@ from pyrogram.client.ext import BaseClient, utils class SendAudio(BaseClient): def send_audio(self, - chat_id: int or str, + chat_id: Union[int, str], audio: str, caption: str = "", parse_mode: str = "", @@ -39,7 +40,10 @@ class SendAudio(BaseClient): thumb: str = None, disable_notification: bool = None, reply_to_message_id: int = None, - reply_markup=None, + reply_markup: Union["pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply"] = None, progress: callable = None, progress_args: tuple = ()): """Use this method to send audio files. @@ -185,7 +189,7 @@ class SendAudio(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_chat_action.py b/pyrogram/client/methods/messages/send_chat_action.py index c519f67b..61e9994f 100644 --- a/pyrogram/client/methods/messages/send_chat_action.py +++ b/pyrogram/client/methods/messages/send_chat_action.py @@ -16,14 +16,16 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api import functions from pyrogram.client.ext import BaseClient, ChatAction class SendChatAction(BaseClient): def send_chat_action(self, - chat_id: int or str, - action: ChatAction or str, + chat_id: Union[int, str], + action: Union[ChatAction, str], progress: int = 0): """Use this method when you need to tell the other party that something is happening on your side. diff --git a/pyrogram/client/methods/messages/send_contact.py b/pyrogram/client/methods/messages/send_contact.py index a5d88f97..d7f93743 100644 --- a/pyrogram/client/methods/messages/send_contact.py +++ b/pyrogram/client/methods/messages/send_contact.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.api import functions, types from pyrogram.client.ext import BaseClient @@ -23,14 +25,17 @@ from pyrogram.client.ext import BaseClient class SendContact(BaseClient): def send_contact(self, - chat_id: int or str, + chat_id: Union[int, str], phone_number: str, first_name: str, last_name: str = "", vcard: str = "", disable_notification: bool = None, reply_to_message_id: int = None, - reply_markup=None): + reply_markup: Union["pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply"] = None): """Use this method to send phone contacts. Args: @@ -87,7 +92,7 @@ class SendContact(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_document.py b/pyrogram/client/methods/messages/send_document.py index 66a65e9d..d7bb62d1 100644 --- a/pyrogram/client/methods/messages/send_document.py +++ b/pyrogram/client/methods/messages/send_document.py @@ -20,6 +20,7 @@ import binascii import mimetypes import os import struct +from typing import Union import pyrogram from pyrogram.api import functions, types @@ -29,14 +30,17 @@ from pyrogram.client.ext import BaseClient, utils class SendDocument(BaseClient): def send_document(self, - chat_id: int or str, + chat_id: Union[int, str], document: str, thumb: str = None, caption: str = "", parse_mode: str = "", disable_notification: bool = None, reply_to_message_id: int = None, - reply_markup=None, + reply_markup: Union["pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply"] = None, progress: callable = None, progress_args: tuple = ()): """Use this method to send general files. @@ -166,7 +170,7 @@ class SendDocument(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_location.py b/pyrogram/client/methods/messages/send_location.py index baa84966..0efdb1df 100644 --- a/pyrogram/client/methods/messages/send_location.py +++ b/pyrogram/client/methods/messages/send_location.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.api import functions, types from pyrogram.client.ext import BaseClient @@ -23,12 +25,15 @@ from pyrogram.client.ext import BaseClient class SendLocation(BaseClient): def send_location(self, - chat_id: int or str, + chat_id: Union[int, str], latitude: float, longitude: float, disable_notification: bool = None, reply_to_message_id: int = None, - reply_markup=None): + reply_markup: Union["pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply"] = None): """Use this method to send points on the map. Args: @@ -79,7 +84,7 @@ class SendLocation(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_media_group.py b/pyrogram/client/methods/messages/send_media_group.py index bc9f6971..d5549089 100644 --- a/pyrogram/client/methods/messages/send_media_group.py +++ b/pyrogram/client/methods/messages/send_media_group.py @@ -20,10 +20,11 @@ import binascii import mimetypes import os import struct +from typing import Union, List +import pyrogram from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid -from pyrogram.client import types as pyrogram_types from pyrogram.client.ext import BaseClient, utils @@ -32,8 +33,8 @@ class SendMediaGroup(BaseClient): # TODO: Return new Message object # TODO: Figure out how to send albums using URLs def send_media_group(self, - chat_id: int or str, - media: list, + chat_id: Union[int, str], + media: List[Union["pyrogram.InputMediaPhoto", "pyrogram.InputMediaVideo"]], disable_notification: bool = None, reply_to_message_id: int = None): """Use this method to send a group of photos or videos as an album. @@ -62,7 +63,7 @@ class SendMediaGroup(BaseClient): for i in media: style = self.html if i.parse_mode.lower() == "html" else self.markdown - if isinstance(i, pyrogram_types.InputMediaPhoto): + if isinstance(i, pyrogram.InputMediaPhoto): if os.path.exists(i.media): media = self.send( functions.messages.UploadMedia( @@ -101,7 +102,7 @@ class SendMediaGroup(BaseClient): access_hash=unpacked[3] ) ) - elif isinstance(i, pyrogram_types.InputMediaVideo): + elif isinstance(i, pyrogram.InputMediaVideo): if os.path.exists(i.media): media = self.send( functions.messages.UploadMedia( diff --git a/pyrogram/client/methods/messages/send_message.py b/pyrogram/client/methods/messages/send_message.py index 77af4db8..a04a67f2 100644 --- a/pyrogram/client/methods/messages/send_message.py +++ b/pyrogram/client/methods/messages/send_message.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.api import functions, types from ...ext import BaseClient @@ -23,13 +25,16 @@ from ...ext import BaseClient class SendMessage(BaseClient): def send_message(self, - chat_id: int or str, + chat_id: Union[int, str], text: str, parse_mode: str = "", disable_web_page_preview: bool = None, disable_notification: bool = None, reply_to_message_id: int = None, - reply_markup=None): + reply_markup: Union["pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply"] = None): """Use this method to send text messages. Args: @@ -99,7 +104,7 @@ class SendMessage(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_photo.py b/pyrogram/client/methods/messages/send_photo.py index 323c2fa5..5b7b3268 100644 --- a/pyrogram/client/methods/messages/send_photo.py +++ b/pyrogram/client/methods/messages/send_photo.py @@ -19,6 +19,7 @@ import binascii import os import struct +from typing import Union import pyrogram from pyrogram.api import functions, types @@ -28,14 +29,17 @@ from pyrogram.client.ext import BaseClient, utils class SendPhoto(BaseClient): def send_photo(self, - chat_id: int or str, + chat_id: Union[int, str], photo: str, caption: str = "", parse_mode: str = "", ttl_seconds: int = None, disable_notification: bool = None, reply_to_message_id: int = None, - reply_markup=None, + reply_markup: Union["pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply"] = None, progress: callable = None, progress_args: tuple = ()): """Use this method to send photos. @@ -161,7 +165,7 @@ class SendPhoto(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_sticker.py b/pyrogram/client/methods/messages/send_sticker.py index fccfb0b5..550bcddb 100644 --- a/pyrogram/client/methods/messages/send_sticker.py +++ b/pyrogram/client/methods/messages/send_sticker.py @@ -19,6 +19,7 @@ import binascii import os import struct +from typing import Union import pyrogram from pyrogram.api import functions, types @@ -28,11 +29,14 @@ from pyrogram.client.ext import BaseClient, utils class SendSticker(BaseClient): def send_sticker(self, - chat_id: int or str, + chat_id: Union[int, str], sticker: str, disable_notification: bool = None, reply_to_message_id: int = None, - reply_markup=None, + reply_markup: Union["pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply"] = None, progress: callable = None, progress_args: tuple = ()): """Use this method to send .webp stickers. @@ -145,7 +149,7 @@ class SendSticker(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_venue.py b/pyrogram/client/methods/messages/send_venue.py index 1155ca79..35d725d1 100644 --- a/pyrogram/client/methods/messages/send_venue.py +++ b/pyrogram/client/methods/messages/send_venue.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.api import functions, types from pyrogram.client.ext import BaseClient @@ -23,7 +25,7 @@ from pyrogram.client.ext import BaseClient class SendVenue(BaseClient): def send_venue(self, - chat_id: int or str, + chat_id: Union[int, str], latitude: float, longitude: float, title: str, @@ -32,7 +34,10 @@ class SendVenue(BaseClient): foursquare_type: str = "", disable_notification: bool = None, reply_to_message_id: int = None, - reply_markup=None): + reply_markup: Union["pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply"] = None): """Use this method to send information about a venue. Args: @@ -101,7 +106,7 @@ class SendVenue(BaseClient): for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_video.py b/pyrogram/client/methods/messages/send_video.py index 47b15d59..c6936cff 100644 --- a/pyrogram/client/methods/messages/send_video.py +++ b/pyrogram/client/methods/messages/send_video.py @@ -20,6 +20,7 @@ import binascii import mimetypes import os import struct +from typing import Union import pyrogram from pyrogram.api import functions, types @@ -29,7 +30,7 @@ from pyrogram.client.ext import BaseClient, utils class SendVideo(BaseClient): def send_video(self, - chat_id: int or str, + chat_id: Union[int, str], video: str, caption: str = "", parse_mode: str = "", @@ -40,7 +41,10 @@ class SendVideo(BaseClient): supports_streaming: bool = True, disable_notification: bool = None, reply_to_message_id: int = None, - reply_markup=None, + reply_markup: Union["pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply"] = None, progress: callable = None, progress_args: tuple = ()): """Use this method to send video files. @@ -188,7 +192,7 @@ class SendVideo(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_video_note.py b/pyrogram/client/methods/messages/send_video_note.py index 61ae0017..75345607 100644 --- a/pyrogram/client/methods/messages/send_video_note.py +++ b/pyrogram/client/methods/messages/send_video_note.py @@ -20,6 +20,7 @@ import binascii import mimetypes import os import struct +from typing import Union import pyrogram from pyrogram.api import functions, types @@ -29,14 +30,17 @@ from pyrogram.client.ext import BaseClient, utils class SendVideoNote(BaseClient): def send_video_note(self, - chat_id: int or str, + chat_id: Union[int, str], video_note: str, duration: int = 0, length: int = 1, thumb: str = None, disable_notification: bool = None, reply_to_message_id: int = None, - reply_markup=None, + reply_markup: Union["pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply"] = None, progress: callable = None, progress_args: tuple = ()): """Use this method to send video messages. @@ -164,7 +168,7 @@ class SendVideoNote(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/messages/send_voice.py b/pyrogram/client/methods/messages/send_voice.py index 4882a87f..52cbc833 100644 --- a/pyrogram/client/methods/messages/send_voice.py +++ b/pyrogram/client/methods/messages/send_voice.py @@ -20,6 +20,7 @@ import binascii import mimetypes import os import struct +from typing import Union import pyrogram from pyrogram.api import functions, types @@ -29,14 +30,17 @@ from pyrogram.client.ext import BaseClient, utils class SendVoice(BaseClient): def send_voice(self, - chat_id: int or str, + chat_id: Union[int, str], voice: str, caption: str = "", parse_mode: str = "", duration: int = 0, disable_notification: bool = None, reply_to_message_id: int = None, - reply_markup=None, + reply_markup: Union["pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply"] = None, progress: callable = None, progress_args: tuple = ()): """Use this method to send audio files. @@ -164,7 +168,7 @@ class SendVoice(BaseClient): else: for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): - return pyrogram.Message.parse( + return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} diff --git a/pyrogram/client/methods/password/change_cloud_password.py b/pyrogram/client/methods/password/change_cloud_password.py index 4b5e86b3..600f58fa 100644 --- a/pyrogram/client/methods/password/change_cloud_password.py +++ b/pyrogram/client/methods/password/change_cloud_password.py @@ -24,7 +24,10 @@ from ...ext import BaseClient class ChangeCloudPassword(BaseClient): - def change_cloud_password(self, current_password: str, new_password: str, new_hint: str = ""): + def change_cloud_password(self, + current_password: str, + new_password: str, + new_hint: str = ""): """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 80d527c4..77c731dd 100644 --- a/pyrogram/client/methods/password/enable_cloud_password.py +++ b/pyrogram/client/methods/password/enable_cloud_password.py @@ -24,7 +24,10 @@ from ...ext import BaseClient class EnableCloudPassword(BaseClient): - def enable_cloud_password(self, password: str, hint: str = "", email: str = ""): + def enable_cloud_password(self, + password: str, + hint: str = "", + email: str = ""): """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 5a9875ff..c82436b7 100644 --- a/pyrogram/client/methods/password/remove_cloud_password.py +++ b/pyrogram/client/methods/password/remove_cloud_password.py @@ -23,7 +23,8 @@ from ...ext import BaseClient class RemoveCloudPassword(BaseClient): - def remove_cloud_password(self, password: str): + def remove_cloud_password(self, + password: str): """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 6f13e17f..4f3c5fde 100644 --- a/pyrogram/client/methods/users/delete_user_profile_photos.py +++ b/pyrogram/client/methods/users/delete_user_profile_photos.py @@ -18,13 +18,15 @@ from base64 import b64decode from struct import unpack +from typing import List, Union from pyrogram.api import functions, types from ...ext import BaseClient class DeleteUserProfilePhotos(BaseClient): - def delete_user_profile_photos(self, id: str or list): + def delete_user_profile_photos(self, + id: Union[str, List[str]]): """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 c7d32968..9072a909 100644 --- a/pyrogram/client/methods/users/get_me.py +++ b/pyrogram/client/methods/users/get_me.py @@ -31,7 +31,7 @@ class GetMe(BaseClient): Raises: :class:`Error ` in case of a Telegram RPC error. """ - return pyrogram.User.parse( + return pyrogram.User._parse( self, self.send( functions.users.GetFullUser( diff --git a/pyrogram/client/methods/users/get_user_profile_photos.py b/pyrogram/client/methods/users/get_user_profile_photos.py index 1403eb79..86ecb74d 100644 --- a/pyrogram/client/methods/users/get_user_profile_photos.py +++ b/pyrogram/client/methods/users/get_user_profile_photos.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.api import functions from ...ext import BaseClient @@ -23,7 +25,7 @@ from ...ext import BaseClient class GetUserProfilePhotos(BaseClient): def get_user_profile_photos(self, - user_id: int or str, + user_id: Union[int, str], offset: int = 0, limit: int = 100): """Use this method to get a list of profile pictures for a user. @@ -48,7 +50,7 @@ class GetUserProfilePhotos(BaseClient): Raises: :class:`Error ` in case of a Telegram RPC error. """ - return pyrogram.UserProfilePhotos.parse( + return pyrogram.UserProfilePhotos._parse( self, self.send( functions.photos.GetUserPhotos( diff --git a/pyrogram/client/methods/users/get_users.py b/pyrogram/client/methods/users/get_users.py index 7251476a..075814ca 100644 --- a/pyrogram/client/methods/users/get_users.py +++ b/pyrogram/client/methods/users/get_users.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 Iterable, Union + import pyrogram from pyrogram.api import functions from ...ext import BaseClient class GetUsers(BaseClient): - def get_users(self, user_ids): + def get_users(self, + user_ids: Iterable[Union[int, str]]): """Use this method to get information about a user. You can retrieve up to 200 users at once. @@ -53,6 +56,6 @@ class GetUsers(BaseClient): users = [] for i in r: - users.append(pyrogram.User.parse(self, i)) + users.append(pyrogram.User._parse(self, i)) return users if is_iterable else users[0] diff --git a/pyrogram/client/methods/users/set_user_profile_photo.py b/pyrogram/client/methods/users/set_user_profile_photo.py index b3ab66b1..68e174d6 100644 --- a/pyrogram/client/methods/users/set_user_profile_photo.py +++ b/pyrogram/client/methods/users/set_user_profile_photo.py @@ -21,7 +21,8 @@ from ...ext import BaseClient class SetUserProfilePhoto(BaseClient): - def set_user_profile_photo(self, photo: str): + def set_user_profile_photo(self, + photo: str): """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 f0ad0396..8c609d98 100644 --- a/pyrogram/client/methods/utilities/download_media.py +++ b/pyrogram/client/methods/utilities/download_media.py @@ -17,14 +17,15 @@ # along with Pyrogram. If not, see . from threading import Event +from typing import Union -from pyrogram.client import types as pyrogram_types +import pyrogram from ...ext import BaseClient class DownloadMedia(BaseClient): def download_media(self, - message: pyrogram_types.Message or str, + message: Union["pyrogram.Message", str], file_name: str = "", block: bool = True, progress: callable = None, @@ -78,9 +79,9 @@ class DownloadMedia(BaseClient): """ error_message = "This message doesn't contain any downloadable media" - if isinstance(message, pyrogram_types.Message): + if isinstance(message, pyrogram.Message): if message.photo: - media = pyrogram_types.Document( + media = pyrogram.Document( file_id=message.photo.sizes[-1].file_id, file_size=message.photo.sizes[-1].file_size, mime_type="", @@ -104,18 +105,18 @@ class DownloadMedia(BaseClient): else: raise ValueError(error_message) elif isinstance(message, ( - pyrogram_types.Photo, - pyrogram_types.PhotoSize, - pyrogram_types.Audio, - pyrogram_types.Document, - pyrogram_types.Video, - pyrogram_types.Voice, - pyrogram_types.VideoNote, - pyrogram_types.Sticker, - pyrogram_types.Animation + pyrogram.Photo, + pyrogram.PhotoSize, + pyrogram.Audio, + pyrogram.Document, + pyrogram.Video, + pyrogram.Voice, + pyrogram.VideoNote, + pyrogram.Sticker, + pyrogram.Animation )): - if isinstance(message, pyrogram_types.Photo): - media = pyrogram_types.Document( + if isinstance(message, pyrogram.Photo): + media = pyrogram.Document( file_id=message.sizes[-1].file_id, file_size=message.sizes[-1].file_size, mime_type="", @@ -125,7 +126,7 @@ class DownloadMedia(BaseClient): else: media = message elif isinstance(message, str): - media = pyrogram_types.Document( + media = pyrogram.Document( file_id=message, file_size=0, mime_type="", diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index 0dede950..25c35456 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -483,7 +483,7 @@ class Message(PyrogramType): else: video = pyrogram.Video._parse(client, doc, video_attributes, file_name) elif types.DocumentAttributeSticker in attributes: - sticker = pyrogram.Sticker.parse( + sticker = pyrogram.Sticker._parse( client, doc, attributes.get(types.DocumentAttributeImageSize, None), attributes[types.DocumentAttributeSticker],