From 854096e9d3124f0d9a5796ec5572aad466e0b865 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 16 Mar 2024 16:37:26 +0100 Subject: [PATCH] Fix typechecks and tests --- client/doc/concepts/chats.rst | 6 +++--- client/doc/modules/types.rst | 6 ++++++ client/src/telethon/_impl/client/events/filters/callback.py | 2 +- client/src/telethon/_impl/client/events/queries.py | 4 +--- client/src/telethon/_impl/client/types/message.py | 2 +- generator/tests/generator_test.py | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/client/doc/concepts/chats.rst b/client/doc/concepts/chats.rst index 39c2b019..31e6582a 100644 --- a/client/doc/concepts/chats.rst +++ b/client/doc/concepts/chats.rst @@ -25,8 +25,8 @@ The following types are chat-like: * The ``'me'`` literal string. This represents the account that is logged in ("yourself"). * An ``'@username'``. The at-sign ``@`` is optional. Note that links are not supported. -* An ``'+1 23'`` phone number string. It must be an ``str`` and start with the plus-sign ``+`` character. -* An ``123`` integer identifier. It must be an ``int`` and cannot be negative. +* An ``'+1 23'`` phone number string. It must be an :class:`str` and start with the plus-sign ``+`` character. +* An ``123`` integer identifier. It must be an :class:`int` and cannot be negative. * An existing :class:`~types.User`, :class:`~types.Group` or :class:`~types.Channel`. * A :class:`~types.PackedChat`. @@ -83,7 +83,7 @@ If you got an Bot API-style ID from somewhere else, you will need to explicitly from telethon.types import PackedChat, PackedType chat = PackedChat(PackedType.BROADCAST, 1234, None) # ...you need to explicitly create a PackedChat with id=1234 and set the corresponding type (a channel). - # The access hash (see below) will be ``None``, which may or may not work. + # The access hash (see below) will be None, which may or may not work. Encountering chats diff --git a/client/doc/modules/types.rst b/client/doc/modules/types.rst index 74278734..38373805 100644 --- a/client/doc/modules/types.rst +++ b/client/doc/modules/types.rst @@ -112,6 +112,12 @@ Private definitions .. autoclass:: OutFileLike +.. currentmodule:: telethon._impl.mtproto.mtp.types + +.. class:: MsgId + + New-type wrapper around :class:`int` used as a message identifier. + .. currentmodule:: telethon._impl.mtsender.sender .. autoclass:: AsyncReader diff --git a/client/src/telethon/_impl/client/events/filters/callback.py b/client/src/telethon/_impl/client/events/filters/callback.py index 64289347..90d5724f 100644 --- a/client/src/telethon/_impl/client/events/filters/callback.py +++ b/client/src/telethon/_impl/client/events/filters/callback.py @@ -20,4 +20,4 @@ class Data(Combinable): def __call__(self, event: Event) -> bool: data = getattr(event, "data", None) - return self._data == data if data is not None else False + return self._data == data if isinstance(data, bytes) else False diff --git a/client/src/telethon/_impl/client/events/queries.py b/client/src/telethon/_impl/client/events/queries.py index a13e79ef..c85764d3 100644 --- a/client/src/telethon/_impl/client/events/queries.py +++ b/client/src/telethon/_impl/client/events/queries.py @@ -79,9 +79,7 @@ class ButtonCallback(Event): """ pid = peer_id(self._raw.peer) - chat = self._chat_map.get(pid) - if not chat: - chat = await self._client._resolve_to_packed(pid) + chat = self._chat_map.get(pid) or await self._client._resolve_to_packed(pid) lst = CherryPickedList(self._client, chat, []) lst._ids.append( diff --git a/client/src/telethon/_impl/client/types/message.py b/client/src/telethon/_impl/client/types/message.py index 8bfa94e4..674e6c74 100644 --- a/client/src/telethon/_impl/client/types/message.py +++ b/client/src/telethon/_impl/client/types/message.py @@ -497,7 +497,7 @@ class Message(metaclass=NoPublicConstructor): else: return False - def __bool__(self): + def __bool__(self) -> bool: return not isinstance(self._raw, types.MessageEmpty) diff --git a/generator/tests/generator_test.py b/generator/tests/generator_test.py index 1835cf18..9275b112 100644 --- a/generator/tests/generator_test.py +++ b/generator/tests/generator_test.py @@ -32,7 +32,7 @@ def test_generic_functions_use_bytes_parameters() -> None: ) result = gen_py_code(functiondefs=definitions) assert "invoke_with_layer" in result - assert "query: bytes" in result + assert "query: _bytes" in result assert "buffer += query" in result