2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 12:57:52 +00:00

Type hint all methods return values

This commit is contained in:
Dan 2018-12-19 15:59:15 +01:00
parent bf0b947253
commit a0355a5cc4
51 changed files with 80 additions and 68 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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.)

View File

@ -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))

View File

@ -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.

View File

@ -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:

View File

@ -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.

View File

@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -16,15 +16,18 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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

View File

@ -16,15 +16,18 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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

View File

@ -17,17 +17,18 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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:

View File

@ -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`.

View File

@ -16,13 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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

View File

@ -16,15 +16,18 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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

View File

@ -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.

View File

@ -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:

View File

@ -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,

View File

@ -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:

View File

@ -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:

View File

@ -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 <pyrogram.Message>` even if a list contains just one element, otherwise if
*message_ids* was an integer, the single forwarded :obj:`Message <pyrogram.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]

View File

@ -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.

View File

@ -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:

View File

@ -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.

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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.

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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 <User>` 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 <pyrogram.Error>` in case of a Telegram RPC error.

View File

@ -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.

View File

@ -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:

View File

@ -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)