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

Add return types (function annotations)

This commit is contained in:
Dan 2018-04-05 00:23:38 +02:00
parent 66347a7140
commit feece7e633

View File

@ -19,7 +19,7 @@ ENTITIES = {
} }
def parse_entities(entities: list): def parse_entities(entities: list) -> list:
output_entities = [] output_entities = []
for entity in entities: for entity in entities:
@ -36,7 +36,7 @@ def parse_entities(entities: list):
return output_entities return output_entities
def parse_user(user: types.User): def parse_user(user: types.User) -> pyrogram.User or None:
return pyrogram.User( return pyrogram.User(
id=user.id, id=user.id,
is_bot=user.bot, is_bot=user.bot,
@ -47,7 +47,7 @@ def parse_user(user: types.User):
) if user else None ) if user else None
def parse_chat(message: types.Message, users: dict, chats: dict): def parse_chat(message: types.Message, users: dict, chats: dict) -> pyrogram.Chat:
if isinstance(message.to_id, types.PeerUser): if isinstance(message.to_id, types.PeerUser):
return parse_user_chat(users[message.to_id.user_id if message.out else message.from_id]) return parse_user_chat(users[message.to_id.user_id if message.out else message.from_id])
elif isinstance(message.to_id, types.PeerChat): elif isinstance(message.to_id, types.PeerChat):
@ -56,7 +56,7 @@ def parse_chat(message: types.Message, users: dict, chats: dict):
return parse_channel_chat(chats[message.to_id.channel_id]) return parse_channel_chat(chats[message.to_id.channel_id])
def parse_user_chat(user: types.User): def parse_user_chat(user: types.User) -> pyrogram.Chat:
return pyrogram.Chat( return pyrogram.Chat(
id=user.id, id=user.id,
type="private", type="private",
@ -66,7 +66,7 @@ def parse_user_chat(user: types.User):
) )
def parse_chat_chat(chat: types.Chat): def parse_chat_chat(chat: types.Chat) -> pyrogram.Chat:
return pyrogram.Chat( return pyrogram.Chat(
id=-chat.id, id=-chat.id,
type="group", type="group",
@ -75,7 +75,7 @@ def parse_chat_chat(chat: types.Chat):
) )
def parse_channel_chat(channel: types.Channel): def parse_channel_chat(channel: types.Channel) -> pyrogram.Chat:
return pyrogram.Chat( return pyrogram.Chat(
id=int("-100" + str(channel.id)), id=int("-100" + str(channel.id)),
type="supergroup" if channel.megagroup else "channel", type="supergroup" if channel.megagroup else "channel",
@ -84,7 +84,7 @@ def parse_channel_chat(channel: types.Channel):
) )
def parse_thumb(thumb: types.PhotoSize or types.PhotoCachedSize): def parse_thumb(thumb: types.PhotoSize or types.PhotoCachedSize) -> pyrogram.PhotoSize or None:
if isinstance(thumb, (types.PhotoSize, types.PhotoCachedSize)): if isinstance(thumb, (types.PhotoSize, types.PhotoCachedSize)):
loc = thumb.location loc = thumb.location
@ -114,7 +114,7 @@ def parse_thumb(thumb: types.PhotoSize or types.PhotoCachedSize):
# TODO: Reorganize code, maybe split parts as well # TODO: Reorganize code, maybe split parts as well
def parse_message(message: types.Message, users: dict, chats: dict): def parse_message(message: types.Message, users: dict, chats: dict) -> pyrogram.Message:
entities = parse_entities(message.entities) entities = parse_entities(message.entities)
forward_from = None forward_from = None
@ -368,7 +368,7 @@ def parse_message(message: types.Message, users: dict, chats: dict):
) )
def parse_message_service(message: types.MessageService, users: dict, chats: dict): def parse_message_service(message: types.MessageService, users: dict, chats: dict) -> pyrogram.Message or None:
action = message.action action = message.action
new_chat_members = None new_chat_members = None
@ -417,7 +417,7 @@ def parse_message_service(message: types.MessageService, users: dict, chats: dic
) )
def decode(s): def decode(s: str) -> bytes:
s = b64decode(s + "=" * (-len(s) % 4), "-_") s = b64decode(s + "=" * (-len(s) % 4), "-_")
r = b"" r = b""
@ -436,7 +436,7 @@ def decode(s):
return r return r
def encode(s): def encode(s: bytes) -> str:
r = b"" r = b""
n = 0 n = 0