Skip to content

Commit

Permalink
Fix cyclic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Oct 19, 2023
1 parent b8b9836 commit 257b5d7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion client/src/telethon/_impl/client/types/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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
Expand Down Expand Up @@ -52,6 +51,8 @@ def chat(self) -> Chat:
"""
The chat where messages are sent in this dialog.
"""
from ..utils import peer_id

return self._chat_map[peer_id(self._raw.peer)]

@property
Expand Down
6 changes: 5 additions & 1 deletion client/src/telethon/_impl/client/types/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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
Expand Down Expand Up @@ -59,6 +58,8 @@ def chat(self) -> Chat:
"""
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
)
Expand Down Expand Up @@ -158,6 +159,8 @@ async def edit(
)

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()
Expand All @@ -179,6 +182,7 @@ async def send(self) -> Message:
await draft.send(clear=False)
"""
from ..utils import generate_random_id

packed = await self._packed_chat()
peer = packed._to_input_peer()
Expand Down
3 changes: 2 additions & 1 deletion client/src/telethon/_impl/client/types/inline_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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
Expand Down Expand Up @@ -51,6 +50,8 @@ async def send(
: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")

Expand Down
7 changes: 6 additions & 1 deletion client/src/telethon/_impl/client/types/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

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
Expand Down Expand Up @@ -132,10 +131,14 @@ def text_markdown(self) -> Optional[str]:

@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(
Expand All @@ -144,6 +147,8 @@ def chat(self) -> Chat:

@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)
Expand Down

0 comments on commit 257b5d7

Please sign in to comment.