From 257b5d74e9fb3288afbaadb5b8fbe4dc01512b66 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 19 Oct 2023 22:41:55 +0200 Subject: [PATCH] Fix cyclic imports --- client/src/telethon/_impl/client/types/dialog.py | 3 ++- client/src/telethon/_impl/client/types/draft.py | 6 +++++- client/src/telethon/_impl/client/types/inline_result.py | 3 ++- client/src/telethon/_impl/client/types/message.py | 7 ++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/client/src/telethon/_impl/client/types/dialog.py b/client/src/telethon/_impl/client/types/dialog.py index 3502f71f..6ca095fa 100644 --- a/client/src/telethon/_impl/client/types/dialog.py +++ b/client/src/telethon/_impl/client/types/dialog.py @@ -3,7 +3,6 @@ from __future__ import annotations from typing import TYPE_CHECKING, Dict, Optional, Self, Union from ...tl import abcs, types -from ..utils import peer_id from .chat import Chat from .draft import Draft from .message import Message @@ -52,6 +51,8 @@ class Dialog(metaclass=NoPublicConstructor): """ The chat where messages are sent in this dialog. """ + from ..utils import peer_id + return self._chat_map[peer_id(self._raw.peer)] @property diff --git a/client/src/telethon/_impl/client/types/draft.py b/client/src/telethon/_impl/client/types/draft.py index 2cd5bdb3..c26cb871 100644 --- a/client/src/telethon/_impl/client/types/draft.py +++ b/client/src/telethon/_impl/client/types/draft.py @@ -6,7 +6,6 @@ from typing import TYPE_CHECKING, Dict, Optional, Self from ...session import PackedChat from ...tl import abcs, functions, types from ..parsers import generate_html_message, generate_markdown_message -from ..utils import expand_peer, generate_random_id, peer_id from .chat import Chat from .message import Message from .meta import NoPublicConstructor @@ -59,6 +58,8 @@ class Draft(metaclass=NoPublicConstructor): """ The chat where the draft will be sent to. """ + from ..utils import expand_peer, peer_id + return self._chat_map.get(peer_id(self._peer)) or expand_peer( self._peer, broadcast=None ) @@ -158,6 +159,8 @@ class Draft(metaclass=NoPublicConstructor): ) async def _packed_chat(self) -> PackedChat: + from ..utils import peer_id + packed = None if chat := self._chat_map.get(peer_id(self._peer)): packed = chat.pack() @@ -179,6 +182,7 @@ class Draft(metaclass=NoPublicConstructor): await draft.send(clear=False) """ + from ..utils import generate_random_id packed = await self._packed_chat() peer = packed._to_input_peer() diff --git a/client/src/telethon/_impl/client/types/inline_result.py b/client/src/telethon/_impl/client/types/inline_result.py index 209271be..4bdd3c53 100644 --- a/client/src/telethon/_impl/client/types/inline_result.py +++ b/client/src/telethon/_impl/client/types/inline_result.py @@ -3,7 +3,6 @@ from __future__ import annotations from typing import TYPE_CHECKING, Optional, Union from ...tl import abcs, functions, types -from ..utils import generate_random_id from .chat import ChatLike from .message import Message from .meta import NoPublicConstructor @@ -51,6 +50,8 @@ class InlineResult(metaclass=NoPublicConstructor): :return: The sent message. """ + from ..utils import generate_random_id + if chat is None and isinstance(self._default_peer, types.InputPeerEmpty): raise ValueError("no target chat was specified") diff --git a/client/src/telethon/_impl/client/types/message.py b/client/src/telethon/_impl/client/types/message.py index cea77e6a..e21a52f8 100644 --- a/client/src/telethon/_impl/client/types/message.py +++ b/client/src/telethon/_impl/client/types/message.py @@ -5,7 +5,6 @@ from typing import TYPE_CHECKING, Any, Dict, Optional, Self, Union from ...tl import abcs, types from ..parsers import generate_html_message, generate_markdown_message -from ..utils import adapt_date, expand_peer, peer_id from .chat import Chat, ChatLike from .file import File from .meta import NoPublicConstructor @@ -132,10 +131,14 @@ class Message(metaclass=NoPublicConstructor): @property def date(self) -> Optional[datetime.datetime]: + from ..utils import adapt_date + return adapt_date(getattr(self._raw, "date", None)) @property def chat(self) -> Chat: + from ..utils import expand_peer, peer_id + peer = self._raw.peer_id or types.PeerUser(user_id=0) broadcast = broadcast = getattr(self._raw, "post", None) return self._chat_map.get(peer_id(peer)) or expand_peer( @@ -144,6 +147,8 @@ class Message(metaclass=NoPublicConstructor): @property def sender(self) -> Optional[Chat]: + from ..utils import expand_peer, peer_id + if (from_ := getattr(self._raw, "from_id", None)) is not None: return self._chat_map.get(peer_id(from_)) or expand_peer( from_, broadcast=getattr(self._raw, "post", None)