Remove messy subclassing in the TelegramClient

Since it was easy to cause MRO inconsistencies, and it's
not really needed now that self is type hinted as the client.
This commit is contained in:
Lonami Exo 2019-06-24 17:48:46 +02:00
parent 4e80e21ba1
commit b6b4ea669d
13 changed files with 15 additions and 34 deletions

View File

@ -2,7 +2,7 @@ import functools
import inspect
import typing
from .users import UserMethods, _NOT_A_REQUEST
from .users import _NOT_A_REQUEST
from .. import helpers, utils
from ..tl import functions, TLRequest
@ -107,7 +107,7 @@ class _TakeoutClient:
return setattr(self.__client, name, value)
class AccountMethods(UserMethods):
class AccountMethods:
def takeout(
self: 'TelegramClient',
finalize: bool = True,

View File

@ -4,8 +4,6 @@ import os
import sys
import typing
from .messageparse import MessageParseMethods
from .users import UserMethods
from .. import utils, helpers, errors, password as pwd_mod
from ..tl import types, functions
@ -13,7 +11,7 @@ if typing.TYPE_CHECKING:
from .telegramclient import TelegramClient
class AuthMethods(MessageParseMethods, UserMethods):
class AuthMethods:
# region Public methods

View File

@ -1,6 +1,5 @@
import typing
from .users import UserMethods
from .. import hints
from ..tl import types, functions, custom
@ -8,7 +7,7 @@ if typing.TYPE_CHECKING:
from .telegramclient import TelegramClient
class BotMethods(UserMethods):
class BotMethods:
async def inline_query(
self: 'TelegramClient',
bot: 'hints.EntityLike',

View File

@ -1,14 +1,10 @@
import typing
from .updates import UpdateMethods
from .. import utils, hints
from ..tl import types, custom
if typing.TYPE_CHECKING:
from .telegramclient import TelegramClient
class ButtonMethods(UpdateMethods):
class ButtonMethods:
@staticmethod
def build_reply_markup(
buttons: 'typing.Optional[hints.MarkupLike]',

View File

@ -3,7 +3,6 @@ import itertools
import string
import typing
from .users import UserMethods
from .. import helpers, utils, hints
from ..requestiter import RequestIter
from ..tl import types, functions, custom
@ -345,7 +344,7 @@ class _ProfilePhotoIter(RequestIter):
self.request.offset_id = result.messages[-1].id
class ChatMethods(UserMethods):
class ChatMethods:
# region Public methods

View File

@ -2,7 +2,6 @@ import asyncio
import itertools
import typing
from .users import UserMethods
from .. import utils, hints
from ..requestiter import RequestIter
from ..tl import types, functions, custom
@ -104,7 +103,7 @@ class _DraftsIter(RequestIter):
return []
class DialogMethods(UserMethods):
class DialogMethods:
# region Public methods

View File

@ -4,7 +4,6 @@ import os
import pathlib
import typing
from .users import UserMethods
from .. import utils, helpers, errors, hints
from ..requestiter import RequestIter
from ..tl import TLObject, types, functions
@ -152,7 +151,7 @@ class _GenericDownloadIter(_DirectDownloadIter):
self.request.offset -= self._stride
class DownloadMethods(UserMethods):
class DownloadMethods:
# region Public methods

View File

@ -2,7 +2,6 @@ import itertools
import re
import typing
from .users import UserMethods
from .. import utils
from ..tl import types
@ -10,7 +9,7 @@ if typing.TYPE_CHECKING:
from .telegramclient import TelegramClient
class MessageParseMethods(UserMethods):
class MessageParseMethods:
# region Public properties

View File

@ -1,9 +1,6 @@
import itertools
import typing
from .buttons import ButtonMethods
from .messageparse import MessageParseMethods
from .uploads import UploadMethods
from .. import utils, errors, hints
from ..requestiter import RequestIter
from ..tl import types, functions
@ -292,7 +289,7 @@ class _IDsIter(RequestIter):
return True # no next chunk, all done in init
class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
class MessageMethods:
# region Public methods

View File

@ -1,13 +1,13 @@
from . import (
AccountMethods, AuthMethods, DownloadMethods, DialogMethods, ChatMethods,
BotMethods, MessageMethods, UploadMethods, ButtonMethods, UpdateMethods,
MessageParseMethods, UserMethods
MessageParseMethods, UserMethods, TelegramBaseClient
)
class TelegramClient(
AccountMethods, AuthMethods, DownloadMethods, DialogMethods, ChatMethods,
BotMethods, MessageMethods, UploadMethods, ButtonMethods, UpdateMethods,
MessageParseMethods, UserMethods
MessageParseMethods, UserMethods, TelegramBaseClient
):
pass

View File

@ -4,7 +4,6 @@ import random
import time
import typing
from .users import UserMethods
from .. import events, utils, errors
from ..events.common import EventBuilder, EventCommon
from ..tl import types, functions
@ -13,7 +12,7 @@ if typing.TYPE_CHECKING:
from .telegramclient import TelegramClient
class UpdateMethods(UserMethods):
class UpdateMethods:
# region Public methods

View File

@ -7,9 +7,6 @@ import re
import typing
from io import BytesIO
from .buttons import ButtonMethods
from .messageparse import MessageParseMethods
from .users import UserMethods
from .. import utils, helpers, hints
from ..tl import types, functions, custom
@ -84,7 +81,7 @@ def _resize_photo_if_needed(
file.seek(before, io.SEEK_SET)
class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
class UploadMethods:
# region Public methods

View File

@ -3,7 +3,6 @@ import itertools
import time
import typing
from .telegrambaseclient import TelegramBaseClient
from .. import errors, utils, hints
from ..errors import MultiError, RPCError
from ..helpers import retry_range
@ -15,7 +14,7 @@ if typing.TYPE_CHECKING:
from .telegramclient import TelegramClient
class UserMethods(TelegramBaseClient):
class UserMethods:
async def __call__(self: 'TelegramClient', request, ordered=False):
requests = (request if utils.is_list_like(request) else (request,))
for r in requests: