Add type hints to all public methods in the client

This commit is contained in:
Lonami Exo
2019-05-03 21:37:27 +02:00
parent c0e506e568
commit cd4b915522
16 changed files with 393 additions and 159 deletions

View File

@@ -1,17 +1,21 @@
import itertools
import re
import typing
from .users import UserMethods
from .. import utils
from ..tl import types
if typing.TYPE_CHECKING:
from .telegramclient import TelegramClient
class MessageParseMethods(UserMethods):
# region Public properties
@property
def parse_mode(self):
def parse_mode(self: 'TelegramClient'):
"""
This property is the default parse mode used when sending messages.
Defaults to `telethon.extensions.markdown`. It will always
@@ -38,14 +42,14 @@ class MessageParseMethods(UserMethods):
return self._parse_mode
@parse_mode.setter
def parse_mode(self, mode):
def parse_mode(self: 'TelegramClient', mode: str):
self._parse_mode = utils.sanitize_parse_mode(mode)
# endregion
# region Private methods
async def _replace_with_mention(self, entities, i, user):
async def _replace_with_mention(self: 'TelegramClient', entities, i, user):
"""
Helper method to replace ``entities[i]`` to mention ``user``,
or do nothing if it can't be found.
@@ -59,7 +63,7 @@ class MessageParseMethods(UserMethods):
except (ValueError, TypeError):
return False
async def _parse_message_text(self, message, parse_mode):
async def _parse_message_text(self: 'TelegramClient', message, parse_mode):
"""
Returns a (parsed message, entities) tuple depending on ``parse_mode``.
"""
@@ -89,7 +93,7 @@ class MessageParseMethods(UserMethods):
return message, msg_entities
def _get_response_message(self, request, result, input_chat):
def _get_response_message(self: 'TelegramClient', request, result, input_chat):
"""
Extracts the response message known a request and Update result.
The request may also be the ID of the message to match.