mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
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:
parent
4e80e21ba1
commit
b6b4ea669d
|
@ -2,7 +2,7 @@ import functools
|
||||||
import inspect
|
import inspect
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .users import UserMethods, _NOT_A_REQUEST
|
from .users import _NOT_A_REQUEST
|
||||||
from .. import helpers, utils
|
from .. import helpers, utils
|
||||||
from ..tl import functions, TLRequest
|
from ..tl import functions, TLRequest
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ class _TakeoutClient:
|
||||||
return setattr(self.__client, name, value)
|
return setattr(self.__client, name, value)
|
||||||
|
|
||||||
|
|
||||||
class AccountMethods(UserMethods):
|
class AccountMethods:
|
||||||
def takeout(
|
def takeout(
|
||||||
self: 'TelegramClient',
|
self: 'TelegramClient',
|
||||||
finalize: bool = True,
|
finalize: bool = True,
|
||||||
|
|
|
@ -4,8 +4,6 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .messageparse import MessageParseMethods
|
|
||||||
from .users import UserMethods
|
|
||||||
from .. import utils, helpers, errors, password as pwd_mod
|
from .. import utils, helpers, errors, password as pwd_mod
|
||||||
from ..tl import types, functions
|
from ..tl import types, functions
|
||||||
|
|
||||||
|
@ -13,7 +11,7 @@ if typing.TYPE_CHECKING:
|
||||||
from .telegramclient import TelegramClient
|
from .telegramclient import TelegramClient
|
||||||
|
|
||||||
|
|
||||||
class AuthMethods(MessageParseMethods, UserMethods):
|
class AuthMethods:
|
||||||
|
|
||||||
# region Public methods
|
# region Public methods
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .users import UserMethods
|
|
||||||
from .. import hints
|
from .. import hints
|
||||||
from ..tl import types, functions, custom
|
from ..tl import types, functions, custom
|
||||||
|
|
||||||
|
@ -8,7 +7,7 @@ if typing.TYPE_CHECKING:
|
||||||
from .telegramclient import TelegramClient
|
from .telegramclient import TelegramClient
|
||||||
|
|
||||||
|
|
||||||
class BotMethods(UserMethods):
|
class BotMethods:
|
||||||
async def inline_query(
|
async def inline_query(
|
||||||
self: 'TelegramClient',
|
self: 'TelegramClient',
|
||||||
bot: 'hints.EntityLike',
|
bot: 'hints.EntityLike',
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .updates import UpdateMethods
|
|
||||||
from .. import utils, hints
|
from .. import utils, hints
|
||||||
from ..tl import types, custom
|
from ..tl import types, custom
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
|
||||||
from .telegramclient import TelegramClient
|
|
||||||
|
|
||||||
|
class ButtonMethods:
|
||||||
class ButtonMethods(UpdateMethods):
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def build_reply_markup(
|
def build_reply_markup(
|
||||||
buttons: 'typing.Optional[hints.MarkupLike]',
|
buttons: 'typing.Optional[hints.MarkupLike]',
|
||||||
|
|
|
@ -3,7 +3,6 @@ import itertools
|
||||||
import string
|
import string
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .users import UserMethods
|
|
||||||
from .. import helpers, utils, hints
|
from .. import helpers, utils, hints
|
||||||
from ..requestiter import RequestIter
|
from ..requestiter import RequestIter
|
||||||
from ..tl import types, functions, custom
|
from ..tl import types, functions, custom
|
||||||
|
@ -345,7 +344,7 @@ class _ProfilePhotoIter(RequestIter):
|
||||||
self.request.offset_id = result.messages[-1].id
|
self.request.offset_id = result.messages[-1].id
|
||||||
|
|
||||||
|
|
||||||
class ChatMethods(UserMethods):
|
class ChatMethods:
|
||||||
|
|
||||||
# region Public methods
|
# region Public methods
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import asyncio
|
||||||
import itertools
|
import itertools
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .users import UserMethods
|
|
||||||
from .. import utils, hints
|
from .. import utils, hints
|
||||||
from ..requestiter import RequestIter
|
from ..requestiter import RequestIter
|
||||||
from ..tl import types, functions, custom
|
from ..tl import types, functions, custom
|
||||||
|
@ -104,7 +103,7 @@ class _DraftsIter(RequestIter):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
class DialogMethods(UserMethods):
|
class DialogMethods:
|
||||||
|
|
||||||
# region Public methods
|
# region Public methods
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .users import UserMethods
|
|
||||||
from .. import utils, helpers, errors, hints
|
from .. import utils, helpers, errors, hints
|
||||||
from ..requestiter import RequestIter
|
from ..requestiter import RequestIter
|
||||||
from ..tl import TLObject, types, functions
|
from ..tl import TLObject, types, functions
|
||||||
|
@ -152,7 +151,7 @@ class _GenericDownloadIter(_DirectDownloadIter):
|
||||||
self.request.offset -= self._stride
|
self.request.offset -= self._stride
|
||||||
|
|
||||||
|
|
||||||
class DownloadMethods(UserMethods):
|
class DownloadMethods:
|
||||||
|
|
||||||
# region Public methods
|
# region Public methods
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import itertools
|
||||||
import re
|
import re
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .users import UserMethods
|
|
||||||
from .. import utils
|
from .. import utils
|
||||||
from ..tl import types
|
from ..tl import types
|
||||||
|
|
||||||
|
@ -10,7 +9,7 @@ if typing.TYPE_CHECKING:
|
||||||
from .telegramclient import TelegramClient
|
from .telegramclient import TelegramClient
|
||||||
|
|
||||||
|
|
||||||
class MessageParseMethods(UserMethods):
|
class MessageParseMethods:
|
||||||
|
|
||||||
# region Public properties
|
# region Public properties
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
import itertools
|
import itertools
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .buttons import ButtonMethods
|
|
||||||
from .messageparse import MessageParseMethods
|
|
||||||
from .uploads import UploadMethods
|
|
||||||
from .. import utils, errors, hints
|
from .. import utils, errors, hints
|
||||||
from ..requestiter import RequestIter
|
from ..requestiter import RequestIter
|
||||||
from ..tl import types, functions
|
from ..tl import types, functions
|
||||||
|
@ -292,7 +289,7 @@ class _IDsIter(RequestIter):
|
||||||
return True # no next chunk, all done in init
|
return True # no next chunk, all done in init
|
||||||
|
|
||||||
|
|
||||||
class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
|
class MessageMethods:
|
||||||
|
|
||||||
# region Public methods
|
# region Public methods
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
from . import (
|
from . import (
|
||||||
AccountMethods, AuthMethods, DownloadMethods, DialogMethods, ChatMethods,
|
AccountMethods, AuthMethods, DownloadMethods, DialogMethods, ChatMethods,
|
||||||
BotMethods, MessageMethods, UploadMethods, ButtonMethods, UpdateMethods,
|
BotMethods, MessageMethods, UploadMethods, ButtonMethods, UpdateMethods,
|
||||||
MessageParseMethods, UserMethods
|
MessageParseMethods, UserMethods, TelegramBaseClient
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TelegramClient(
|
class TelegramClient(
|
||||||
AccountMethods, AuthMethods, DownloadMethods, DialogMethods, ChatMethods,
|
AccountMethods, AuthMethods, DownloadMethods, DialogMethods, ChatMethods,
|
||||||
BotMethods, MessageMethods, UploadMethods, ButtonMethods, UpdateMethods,
|
BotMethods, MessageMethods, UploadMethods, ButtonMethods, UpdateMethods,
|
||||||
MessageParseMethods, UserMethods
|
MessageParseMethods, UserMethods, TelegramBaseClient
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -4,7 +4,6 @@ import random
|
||||||
import time
|
import time
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .users import UserMethods
|
|
||||||
from .. import events, utils, errors
|
from .. import events, utils, errors
|
||||||
from ..events.common import EventBuilder, EventCommon
|
from ..events.common import EventBuilder, EventCommon
|
||||||
from ..tl import types, functions
|
from ..tl import types, functions
|
||||||
|
@ -13,7 +12,7 @@ if typing.TYPE_CHECKING:
|
||||||
from .telegramclient import TelegramClient
|
from .telegramclient import TelegramClient
|
||||||
|
|
||||||
|
|
||||||
class UpdateMethods(UserMethods):
|
class UpdateMethods:
|
||||||
|
|
||||||
# region Public methods
|
# region Public methods
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,6 @@ import re
|
||||||
import typing
|
import typing
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from .buttons import ButtonMethods
|
|
||||||
from .messageparse import MessageParseMethods
|
|
||||||
from .users import UserMethods
|
|
||||||
from .. import utils, helpers, hints
|
from .. import utils, helpers, hints
|
||||||
from ..tl import types, functions, custom
|
from ..tl import types, functions, custom
|
||||||
|
|
||||||
|
@ -84,7 +81,7 @@ def _resize_photo_if_needed(
|
||||||
file.seek(before, io.SEEK_SET)
|
file.seek(before, io.SEEK_SET)
|
||||||
|
|
||||||
|
|
||||||
class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
|
class UploadMethods:
|
||||||
|
|
||||||
# region Public methods
|
# region Public methods
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ import itertools
|
||||||
import time
|
import time
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .telegrambaseclient import TelegramBaseClient
|
|
||||||
from .. import errors, utils, hints
|
from .. import errors, utils, hints
|
||||||
from ..errors import MultiError, RPCError
|
from ..errors import MultiError, RPCError
|
||||||
from ..helpers import retry_range
|
from ..helpers import retry_range
|
||||||
|
@ -15,7 +14,7 @@ if typing.TYPE_CHECKING:
|
||||||
from .telegramclient import TelegramClient
|
from .telegramclient import TelegramClient
|
||||||
|
|
||||||
|
|
||||||
class UserMethods(TelegramBaseClient):
|
class UserMethods:
|
||||||
async def __call__(self: 'TelegramClient', request, ordered=False):
|
async def __call__(self: 'TelegramClient', request, ordered=False):
|
||||||
requests = (request if utils.is_list_like(request) else (request,))
|
requests = (request if utils.is_list_like(request) else (request,))
|
||||||
for r in requests:
|
for r in requests:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user