From 9fd572d8a221e92558fe6f5d649b16478a0eca84 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Wed, 26 Mar 2025 22:05:05 +0700 Subject: [PATCH] pyrofork: Cleanup codes Signed-off-by: wulan17 --- compiler/api/compiler.py | 18 ++++----- compiler/docs/compiler.py | 4 +- docs/source/conf.py | 2 +- pyrogram/__init__.py | 22 ++++++++-- pyrogram/client.py | 40 +++++++++---------- pyrogram/connection/__init__.py | 4 ++ pyrogram/connection/connection.py | 2 +- pyrogram/connection/transport/tcp/__init__.py | 10 +++++ pyrogram/connection/transport/tcp/tcp.py | 1 - pyrogram/crypto/mtproto.py | 2 +- pyrogram/crypto/prime.py | 4 +- pyrogram/dispatcher.py | 4 +- pyrogram/enums/chat_event_action.py | 18 ++++----- pyrogram/errors/__init__.py | 8 ++++ pyrogram/handlers/__init__.py | 29 +++++++++++++- pyrogram/handlers/conversation_handler.py | 1 + .../deleted_bot_business_messages_handler.py | 3 +- pyrogram/handlers/deleted_messages_handler.py | 3 +- pyrogram/helpers/__init__.py | 13 +++++- pyrogram/helpers/helpers.py | 4 +- pyrogram/methods/advanced/save_file.py | 1 - pyrogram/methods/auth/connect.py | 1 + pyrogram/methods/auth/disconnect.py | 1 + pyrogram/methods/auth/get_active_sessions.py | 2 - pyrogram/methods/auth/initialize.py | 1 + pyrogram/methods/auth/send_code.py | 1 + pyrogram/methods/auth/sign_in_bot.py | 1 + pyrogram/methods/auth/terminate.py | 1 + .../business/get_business_connection.py | 5 +-- pyrogram/methods/chats/ban_chat_member.py | 3 +- pyrogram/methods/chats/close_forum_topic.py | 2 +- pyrogram/methods/chats/close_general_topic.py | 2 +- pyrogram/methods/chats/delete_forum_topic.py | 2 +- pyrogram/methods/chats/edit_forum_topic.py | 2 +- pyrogram/methods/chats/edit_general_topic.py | 2 +- pyrogram/methods/chats/get_chat_member.py | 3 +- pyrogram/methods/chats/get_forum_topics.py | 1 - .../methods/chats/get_forum_topics_by_id.py | 3 +- pyrogram/methods/chats/hide_general_topic.py | 1 - pyrogram/methods/chats/reopen_forum_topic.py | 2 +- .../methods/chats/reopen_general_topic.py | 2 +- pyrogram/methods/chats/set_chat_photo.py | 3 +- .../methods/chats/unhide_general_topic.py | 2 +- .../methods/decorators/on_shipping_query.py | 2 +- pyrogram/methods/messages/copy_media_group.py | 8 +++- pyrogram/methods/messages/get_messages.py | 2 +- pyrogram/methods/messages/send_web_page.py | 1 - pyrogram/methods/payments/convert_gift.py | 3 -- pyrogram/methods/users/delete_stories.py | 3 +- pyrogram/methods/users/edit_story.py | 15 ++++--- pyrogram/methods/users/send_story.py | 15 ++++--- pyrogram/nav/__init__.py | 6 ++- pyrogram/parser/__init__.py | 4 ++ pyrogram/parser/markdown.py | 3 +- pyrogram/raw/__init__.py | 8 ++++ pyrogram/raw/core/__init__.py | 21 ++++++++++ pyrogram/raw/core/primitives/__init__.py | 14 +++++++ pyrogram/session/__init__.py | 5 +++ pyrogram/session/internals/__init__.py | 6 +++ pyrogram/storage/__init__.py | 10 +++++ pyrogram/types/__init__.py | 5 +++ .../types/authorization/active_sessions.py | 3 +- .../bots_and_keyboards/game_high_score.py | 13 +++++- .../bots_and_keyboards/requested_chats.py | 2 +- .../bots_and_keyboards/requested_user.py | 2 +- pyrogram/types/business/shipping_option.py | 3 -- pyrogram/types/business/shipping_query.py | 3 +- pyrogram/types/inline_mode/inline_query.py | 8 +++- .../messages_and_media/alternative_video.py | 2 +- .../messages_and_media/exported_story_link.py | 1 - pyrogram/types/messages_and_media/giveaway.py | 2 - .../media_area_coordinates.py | 2 +- pyrogram/types/messages_and_media/message.py | 8 ++-- .../messages_and_media/message_entity.py | 8 +++- .../messages_and_media/read_participant.py | 2 +- pyrogram/types/messages_and_media/sticker.py | 2 +- .../types/messages_and_media/stickerset.py | 3 -- pyrogram/types/messages_and_media/story.py | 16 ++++---- .../messages_and_media/transcribed_audio.py | 2 +- .../messages_and_media/translated_text.py | 1 - pyrogram/types/messages_and_media/video.py | 2 +- .../messages_and_media/web_page_empty.py | 2 - .../messages_and_media/web_page_preview.py | 1 - pyrogram/types/payments/gift.py | 18 ++++----- pyrogram/types/payments/gift_attribute.py | 5 +-- pyrogram/types/payments/gift_code.py | 9 ++++- pyrogram/types/payments/gifted_premium.py | 4 +- .../types/payments/input_stars_transaction.py | 2 - pyrogram/types/payments/invoice.py | 4 +- pyrogram/types/payments/payment_form.py | 2 +- pyrogram/types/payments/payment_info.py | 2 + pyrogram/types/payments/stars_transaction.py | 3 +- pyrogram/types/payments/successful_payment.py | 2 + pyrogram/types/user_and_chats/birthday.py | 3 -- .../types/user_and_chats/business_info.py | 4 +- .../types/user_and_chats/business_message.py | 4 +- .../user_and_chats/business_recipients.py | 4 +- pyrogram/types/user_and_chats/chat.py | 17 ++++++-- .../user_and_chats/forum_topic_deleted.py | 3 +- 99 files changed, 347 insertions(+), 194 deletions(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 07435778..e918222b 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -130,7 +130,7 @@ def get_type_hint(type: str) -> str: return f"Optional[{type}] = None" if is_flag else type else: ns, name = type.split(".") if "." in type else ("", type) - type = f'"raw.base.' + ".".join([ns, name]).strip(".") + '"' + type = '"raw.base.' + ".".join([ns, name]).strip(".") + '"' return f'{type}{" = None" if is_flag else ""}' @@ -430,11 +430,11 @@ def start(format: bool = False): if function_docs: docstring += function_docs["desc"] + "\n" else: - docstring += f"Telegram API function." + docstring += "Telegram API function." docstring += f"\n\n Details:\n - Layer: ``{layer}``\n - ID: ``{c.id[2:].upper()}``\n\n" - docstring += f" Parameters:\n " + \ - (f"\n ".join(docstring_args) if docstring_args else "No parameters required.\n") + docstring += " Parameters:\n " + \ + ("\n ".join(docstring_args) if docstring_args else "No parameters required.\n") if c.section == "functions": docstring += "\n Returns:\n " + get_docstring_arg_type(c.qualtype) @@ -442,12 +442,12 @@ def start(format: bool = False): references, count = get_references(c.qualname, "constructors") if references: - docstring += f"\n Functions:\n This object can be returned by " \ + docstring += "\n Functions:\n This object can be returned by " \ f"{count} function{'s' if count > 1 else ''}.\n\n" \ - f" .. currentmodule:: pyrogram.raw.functions\n\n" \ - f" .. autosummary::\n" \ - f" :nosignatures:\n\n" \ - f" " + references + " .. currentmodule:: pyrogram.raw.functions\n\n" \ + " .. autosummary::\n" \ + " :nosignatures:\n\n" \ + " " + references write_types = read_types = "" if c.has_flags else "# No flags\n " diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 4130dc91..39c037fb 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -449,7 +449,7 @@ def pyrogram_api(): fmt_keys = {} for k, v in categories.items(): - name, *methods = get_title_list(v) + _, *methods = get_title_list(v) fmt_keys.update({k: "\n ".join("{0} <{0}>".format(m) for m in methods)}) for method in methods: @@ -740,7 +740,7 @@ def pyrogram_api(): fmt_keys = {} for k, v in categories.items(): - name, *types = get_title_list(v) + _, *types = get_title_list(v) fmt_keys.update({k: "\n ".join(types)}) diff --git a/docs/source/conf.py b/docs/source/conf.py index 60c8101e..946989f3 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -29,7 +29,7 @@ from pygments.styles.friendly import FriendlyStyle FriendlyStyle.background_color = "#f3f2f1" project = "Pyrofork" -copyright = f"2022-present, Mayuri-Chan" +copyright = "2022-present, Mayuri-Chan" author = "Mayuri-Chan" version = ".".join(__version__.split(".")[:-1]) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index b5d3b5a5..7417ad62 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -37,8 +37,24 @@ class ContinuePropagation(StopAsyncIteration): pass -from . import raw, types, filters, handlers, emoji, enums -from .client import Client -from .sync import idle, compose +from . import raw, types, filters, handlers, emoji, enums # pylint: disable=wrong-import-position +from .client import Client # pylint: disable=wrong-import-position +from .sync import idle, compose # pylint: disable=wrong-import-position crypto_executor = ThreadPoolExecutor(1, thread_name_prefix="CryptoWorker") + +__all__ = [ + "Client", + "idle", + "compose", + "crypto_executor", + "StopTransmission", + "StopPropagation", + "ContinuePropagation", + "raw", + "types", + "filters", + "handlers", + "emoji", + "enums", +] diff --git a/pyrogram/client.py b/pyrogram/client.py index 5c19df82..edf1c68d 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -33,7 +33,7 @@ from importlib import import_module from io import StringIO, BytesIO from mimetypes import MimeTypes from pathlib import Path -from typing import Union, List, Optional, Callable, AsyncGenerator, Type, Tuple +from typing import Union, List, Optional, Callable, AsyncGenerator, Tuple import pyrogram from pyrogram import __version__, __license__ @@ -51,24 +51,26 @@ from pyrogram.handlers.handler import Handler from pyrogram.methods import Methods from pyrogram.session import Auth, Session from pyrogram.storage import FileStorage, MemoryStorage, Storage +from pyrogram.types import User, TermsOfService +from pyrogram.utils import ainput +from .connection import Connection +from .connection.transport import TCPAbridged +from .dispatcher import Dispatcher +from .file_id import FileId, FileType, ThumbnailSource +from .mime_types import mime_types +from .parser import Parser +from .session.internals import MsgId + +log = logging.getLogger(__name__) +MONGO_AVAIL = False + try: import pymongo except Exception: pass else: from pyrogram.storage import MongoStorage -from pyrogram.types import User, TermsOfService -from pyrogram.utils import ainput -from .connection import Connection -from .connection.transport import TCP, TCPAbridged -from .dispatcher import Dispatcher -from .file_id import FileId, FileType, ThumbnailSource -from .filters import Filter -from .mime_types import mime_types -from .parser import Parser -from .session.internals import MsgId - -log = logging.getLogger(__name__) + MONGO_AVAIL = True class Client(Methods): @@ -316,9 +318,7 @@ class Client(Methods): elif self.in_memory: self.storage = MemoryStorage(self.name) elif self.mongodb: - try: - import pymongo - except Exception: + if not MONGO_AVAIL: log.warning( "pymongo is missing! " "Using MemoryStorage as session storage" @@ -888,7 +888,7 @@ class Client(Methods): count = 0 if not include: - for current_root, dirnames, filenames in os.walk(root.replace(".", "/")): + for current_root, _, filenames in os.walk(root.replace(".", "/")): namespace = current_root.replace("/", ".").replace("\\", ".") if "__pycache__" in namespace: continue @@ -953,7 +953,7 @@ class Client(Methods): ) count += 1 - except Exception as e: + except Exception: pass else: for path, handlers in include: @@ -1042,7 +1042,7 @@ class Client(Methods): ) count += 1 - except Exception as e: + except Exception: pass if handlers is None: @@ -1106,7 +1106,7 @@ class Client(Methods): async def handle_download(self, packet): file_id, directory, file_name, in_memory, file_size, progress, progress_args = packet - os.makedirs(directory, exist_ok=True) if not in_memory else None + _ = os.makedirs(directory, exist_ok=True) if not in_memory else None temp_file_path = os.path.abspath(re.sub("\\\\", "/", os.path.join(directory, file_name))) + ".temp" file = BytesIO() if in_memory else open(temp_file_path, "wb") diff --git a/pyrogram/connection/__init__.py b/pyrogram/connection/__init__.py index 9dc28845..9f67f1a9 100644 --- a/pyrogram/connection/__init__.py +++ b/pyrogram/connection/__init__.py @@ -18,3 +18,7 @@ # along with Pyrofork. If not, see . from .connection import Connection + +__all__ = [ + "Connection" +] diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index 53ac12bd..1f100acc 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -52,7 +52,7 @@ class Connection: self.protocol: Optional[TCP] = None async def connect(self) -> None: - for i in range(Connection.MAX_CONNECTION_ATTEMPTS): + for _ in range(Connection.MAX_CONNECTION_ATTEMPTS): self.protocol = self.protocol_factory(ipv6=self.ipv6, proxy=self.proxy) try: diff --git a/pyrogram/connection/transport/tcp/__init__.py b/pyrogram/connection/transport/tcp/__init__.py index 2a906a2b..be86f6b4 100644 --- a/pyrogram/connection/transport/tcp/__init__.py +++ b/pyrogram/connection/transport/tcp/__init__.py @@ -23,3 +23,13 @@ from .tcp_abridged_o import TCPAbridgedO from .tcp_full import TCPFull from .tcp_intermediate import TCPIntermediate from .tcp_intermediate_o import TCPIntermediateO + +__all__ = [ + "TCP", + "Proxy", + "TCPAbridged", + "TCPAbridgedO", + "TCPFull", + "TCPIntermediate", + "TCPIntermediateO" +] diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index a0f4a15a..1848ba35 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -21,7 +21,6 @@ import asyncio import ipaddress import logging import socket -from concurrent.futures import ThreadPoolExecutor from typing import Tuple, Dict, TypedDict, Optional import socks diff --git a/pyrogram/crypto/mtproto.py b/pyrogram/crypto/mtproto.py index 6b2ab3c4..e17bf345 100644 --- a/pyrogram/crypto/mtproto.py +++ b/pyrogram/crypto/mtproto.py @@ -71,7 +71,7 @@ def unpack( message = Message.read(data) except KeyError as e: if e.args[0] == 0: - raise ConnectionError(f"Received empty data. Check your internet connection.") + raise ConnectionError("Received empty data. Check your internet connection.") left = data.read().hex() diff --git a/pyrogram/crypto/prime.py b/pyrogram/crypto/prime.py index ee806525..ef9fe556 100644 --- a/pyrogram/crypto/prime.py +++ b/pyrogram/crypto/prime.py @@ -55,7 +55,7 @@ def decompose(pq: int) -> int: while g == 1: x = y - for i in range(r): + for _ in range(r): y = (pow(y, 2, pq) + c) % pq k = 0 @@ -63,7 +63,7 @@ def decompose(pq: int) -> int: while k < r and g == 1: ys = y - for i in range(min(m, r - k)): + for _ in range(min(m, r - k)): y = (pow(y, 2, pq) + c) % pq q = q * (abs(x - y)) % pq diff --git a/pyrogram/dispatcher.py b/pyrogram/dispatcher.py index 920d515d..5cb97b5e 100644 --- a/pyrogram/dispatcher.py +++ b/pyrogram/dispatcher.py @@ -23,7 +23,7 @@ import logging from collections import OrderedDict import pyrogram -from pyrogram import errors, raw, types, utils +from pyrogram import raw, types, utils from pyrogram.handlers.handler import Handler from pyrogram.handlers import ( BotBusinessConnectHandler, @@ -266,7 +266,7 @@ class Dispatcher: async def start(self): if not self.client.no_updates: - for i in range(self.client.workers): + for _ in range(self.client.workers): self.locks_list.append(asyncio.Lock()) self.handler_worker_tasks.append( diff --git a/pyrogram/enums/chat_event_action.py b/pyrogram/enums/chat_event_action.py index 12355b66..cfaa6758 100644 --- a/pyrogram/enums/chat_event_action.py +++ b/pyrogram/enums/chat_event_action.py @@ -35,13 +35,13 @@ class ChatEventAction(AutoName): "The linked chat has been changed (see ``old_linked_chat`` and ``new_linked_chat``)" # LOCATION_CHANGED = auto() - "" + # "" PHOTO_CHANGED = auto() "The chat photo has been changed (see ``old_photo`` and ``new_photo``)" # STICKER_SET_CHANGED = auto() - "" + # "" TITLE_CHANGED = auto() "the chat title has been changed (see ``old_title`` and ``new_title``)" @@ -56,7 +56,7 @@ class ChatEventAction(AutoName): "a message has been deleted (see ``deleted_message``)" # VOICE_CHAT_DISCARDED = auto() - "" + # "" MESSAGE_EDITED = auto() "a message has been edited (see ``old_message`` and ``new_message``)" @@ -77,13 +77,13 @@ class ChatEventAction(AutoName): "a member joined by themselves. (see ``user``)" # MEMBER_JOINED_BY_LINK = auto() - "" + # "" MEMBER_LEFT = auto() "a member left by themselves. (see ``user``)" # MEMBER_MUTED = auto() - "" + # "" ADMINISTRATOR_PRIVILEGES_CHANGED = auto() "a chat member has been promoted/demoted or their administrator privileges has changed (see ``old_administrator_privileges`` and ``new_administrator_privileges``)" @@ -92,19 +92,19 @@ class ChatEventAction(AutoName): "a chat member has been restricted/unrestricted or banned/unbanned, or their permissions has changed (see ``old_member_permissions`` and ``new_member_permissions``)" # MEMBER_UNMUTED = auto() - "" + # "" # MEMBER_VOLUME_CHANGED = auto() - "" + # "" # VIDEO_CHAT_STARTED = auto() - "" + # "" POLL_STOPPED = auto() "a poll has been stopped (see ``stopped_poll``)" # VOICE_CHAT_SETTINGS_CHANGED = auto() - "" + # "" INVITES_ENABLED = auto() "the chat invitation has been enabled or disabled (see ``invites_enabled``)" diff --git a/pyrogram/errors/__init__.py b/pyrogram/errors/__init__.py index f74d8e57..d4a93ea5 100644 --- a/pyrogram/errors/__init__.py +++ b/pyrogram/errors/__init__.py @@ -65,3 +65,11 @@ class CDNFileHashMismatch(SecurityError): def __init__(self, msg: str = None): super().__init__("A CDN file hash mismatch has occurred." if msg is None else msg) + +__all__ = [ + "BadMsgNotification", + "SecurityError", + "SecurityCheckMismatch", + "CDNFileHashMismatch", + "UnknownError" +] diff --git a/pyrogram/handlers/__init__.py b/pyrogram/handlers/__init__.py index b4611cc6..6f1c6744 100644 --- a/pyrogram/handlers/__init__.py +++ b/pyrogram/handlers/__init__.py @@ -33,7 +33,6 @@ from .error_handler import ErrorHandler from .inline_query_handler import InlineQueryHandler from .message_handler import MessageHandler from .poll_handler import PollHandler -from .pre_checkout_query_handler import PreCheckoutQueryHandler from .purchased_paid_media_handler import PurchasedPaidMediaHandler from .raw_update_handler import RawUpdateHandler from .user_status_handler import UserStatusHandler @@ -42,3 +41,31 @@ from .message_reaction_updated_handler import MessageReactionUpdatedHandler from .message_reaction_count_updated_handler import MessageReactionCountUpdatedHandler from .pre_checkout_query_handler import PreCheckoutQueryHandler from .shipping_query_handler import ShippingQueryHandler + +__all__ = [ + "BotBusinessConnectHandler", + "BotBusinessMessageHandler", + "CallbackQueryHandler", + "ChatJoinRequestHandler", + "ChatMemberUpdatedHandler", + "ConversationHandler", + "ChosenInlineResultHandler", + "DeletedMessagesHandler", + "DeletedBotBusinessMessagesHandler", + "DisconnectHandler", + "EditedMessageHandler", + "EditedBotBusinessMessageHandler", + "ErrorHandler", + "InlineQueryHandler", + "MessageHandler", + "PollHandler", + "PreCheckoutQueryHandler", + "PurchasedPaidMediaHandler", + "RawUpdateHandler", + "UserStatusHandler", + "StoryHandler", + "MessageReactionUpdatedHandler", + "MessageReactionCountUpdatedHandler", + "PreCheckoutQueryHandler", + "ShippingQueryHandler", +] diff --git a/pyrogram/handlers/conversation_handler.py b/pyrogram/handlers/conversation_handler.py index b3eccf0e..30b40425 100644 --- a/pyrogram/handlers/conversation_handler.py +++ b/pyrogram/handlers/conversation_handler.py @@ -61,6 +61,7 @@ class ConversationHandler(MessageHandler, CallbackQueryHandler): return True @staticmethod + # pylint: disable=method-hidden async def callback(_, __): pass diff --git a/pyrogram/handlers/deleted_bot_business_messages_handler.py b/pyrogram/handlers/deleted_bot_business_messages_handler.py index 0e214e27..875a0213 100644 --- a/pyrogram/handlers/deleted_bot_business_messages_handler.py +++ b/pyrogram/handlers/deleted_bot_business_messages_handler.py @@ -58,5 +58,4 @@ class DeletedBotBusinessMessagesHandler(Handler): for message in messages: if await super().check(client, message): return True - else: - return False + return False diff --git a/pyrogram/handlers/deleted_messages_handler.py b/pyrogram/handlers/deleted_messages_handler.py index 809cfac7..889ff160 100644 --- a/pyrogram/handlers/deleted_messages_handler.py +++ b/pyrogram/handlers/deleted_messages_handler.py @@ -58,5 +58,4 @@ class DeletedMessagesHandler(Handler): for message in messages: if await super().check(client, message): return True - else: - return False + return False diff --git a/pyrogram/helpers/__init__.py b/pyrogram/helpers/__init__.py index 786d7e01..2ce82949 100644 --- a/pyrogram/helpers/__init__.py +++ b/pyrogram/helpers/__init__.py @@ -13,4 +13,15 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with pyromod. If not, see . """ -from .helpers import ikb, bki, ntb, btn, kb, kbtn, array_chunk, force_reply \ No newline at end of file +from .helpers import ikb, bki, ntb, btn, kb, kbtn, array_chunk, force_reply + +__all__ = [ + "ikb", + "bki", + "ntb", + "btn", + "kb", + "kbtn", + "array_chunk", + "force_reply" +] diff --git a/pyrogram/helpers/helpers.py b/pyrogram/helpers/helpers.py index 8aecc170..84f05f38 100644 --- a/pyrogram/helpers/helpers.py +++ b/pyrogram/helpers/helpers.py @@ -101,9 +101,9 @@ def kb(rows=None, **kwargs): line = [] for button in row: button_type = type(button) - if button_type == str: + if isinstance(button_type, str): button = KeyboardButton(button) - elif button_type == dict: + elif isinstance(button_type, dict): button = KeyboardButton(**button) line.append(button) diff --git a/pyrogram/methods/advanced/save_file.py b/pyrogram/methods/advanced/save_file.py index 7eae0469..cf6593da 100644 --- a/pyrogram/methods/advanced/save_file.py +++ b/pyrogram/methods/advanced/save_file.py @@ -23,7 +23,6 @@ import inspect import io import logging import math -import os from hashlib import md5 from pathlib import PurePath from typing import Union, BinaryIO, Callable diff --git a/pyrogram/methods/auth/connect.py b/pyrogram/methods/auth/connect.py index 0858a832..4a57035e 100644 --- a/pyrogram/methods/auth/connect.py +++ b/pyrogram/methods/auth/connect.py @@ -35,6 +35,7 @@ class Connect: Raises: ConnectionError: In case you try to connect an already connected client. """ + # pylint: disable=access-member-before-definition if self.is_connected: raise ConnectionError("Client is already connected") diff --git a/pyrogram/methods/auth/disconnect.py b/pyrogram/methods/auth/disconnect.py index 51dc2006..2b7441e1 100644 --- a/pyrogram/methods/auth/disconnect.py +++ b/pyrogram/methods/auth/disconnect.py @@ -30,6 +30,7 @@ class Disconnect: ConnectionError: In case you try to disconnect an already disconnected client or in case you try to disconnect a client that needs to be terminated first. """ + # pylint: disable=access-member-before-definition if not self.is_connected: raise ConnectionError("Client is already disconnected") diff --git a/pyrogram/methods/auth/get_active_sessions.py b/pyrogram/methods/auth/get_active_sessions.py index d8c906b8..a1b3e404 100644 --- a/pyrogram/methods/auth/get_active_sessions.py +++ b/pyrogram/methods/auth/get_active_sessions.py @@ -16,8 +16,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import List - import pyrogram from pyrogram import raw, types diff --git a/pyrogram/methods/auth/initialize.py b/pyrogram/methods/auth/initialize.py index 1d18508b..f08778fd 100644 --- a/pyrogram/methods/auth/initialize.py +++ b/pyrogram/methods/auth/initialize.py @@ -41,6 +41,7 @@ class Initialize: if not self.is_connected: raise ConnectionError("Can't initialize a disconnected client") + # pylint: disable=access-member-before-definition if self.is_initialized: raise ConnectionError("Client is already initialized") diff --git a/pyrogram/methods/auth/send_code.py b/pyrogram/methods/auth/send_code.py index 9d198fbf..ba4d3283 100644 --- a/pyrogram/methods/auth/send_code.py +++ b/pyrogram/methods/auth/send_code.py @@ -61,6 +61,7 @@ class SendCode: ) ) except (PhoneMigrate, NetworkMigrate) as e: + # pylint: disable=access-member-before-definition await self.session.stop() await self.storage.dc_id(e.value) diff --git a/pyrogram/methods/auth/sign_in_bot.py b/pyrogram/methods/auth/sign_in_bot.py index 59147daa..231f6d9b 100644 --- a/pyrogram/methods/auth/sign_in_bot.py +++ b/pyrogram/methods/auth/sign_in_bot.py @@ -58,6 +58,7 @@ class SignInBot: ) ) except UserMigrate as e: + # pylint: disable=access-member-before-definition await self.session.stop() await self.storage.dc_id(e.value) diff --git a/pyrogram/methods/auth/terminate.py b/pyrogram/methods/auth/terminate.py index 4bbc2341..2b62e82c 100644 --- a/pyrogram/methods/auth/terminate.py +++ b/pyrogram/methods/auth/terminate.py @@ -37,6 +37,7 @@ class Terminate: Raises: ConnectionError: In case you try to terminate a client that is already terminated. """ + # pylint: disable=access-member-before-definition if not self.is_initialized: raise ConnectionError("Client is already terminated") diff --git a/pyrogram/methods/business/get_business_connection.py b/pyrogram/methods/business/get_business_connection.py index 5fe7dc56..7a479c4e 100644 --- a/pyrogram/methods/business/get_business_connection.py +++ b/pyrogram/methods/business/get_business_connection.py @@ -16,11 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from datetime import datetime -from typing import Union, List - import pyrogram -from pyrogram import types, utils, raw +from pyrogram import types, raw class GetBusinessConnection: diff --git a/pyrogram/methods/chats/ban_chat_member.py b/pyrogram/methods/chats/ban_chat_member.py index 2713ea40..58d9d61a 100644 --- a/pyrogram/methods/chats/ban_chat_member.py +++ b/pyrogram/methods/chats/ban_chat_member.py @@ -117,5 +117,4 @@ class BanChatMember: {i.id: i for i in r.users}, {i.id: i for i in r.chats} ) - else: - return True + return True diff --git a/pyrogram/methods/chats/close_forum_topic.py b/pyrogram/methods/chats/close_forum_topic.py index fb4c537f..222367d0 100644 --- a/pyrogram/methods/chats/close_forum_topic.py +++ b/pyrogram/methods/chats/close_forum_topic.py @@ -15,9 +15,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . + import pyrogram from pyrogram import raw -from pyrogram import types from typing import Union diff --git a/pyrogram/methods/chats/close_general_topic.py b/pyrogram/methods/chats/close_general_topic.py index 2f915669..d4090ede 100644 --- a/pyrogram/methods/chats/close_general_topic.py +++ b/pyrogram/methods/chats/close_general_topic.py @@ -15,9 +15,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . + import pyrogram from pyrogram import raw -from pyrogram import types from typing import Union diff --git a/pyrogram/methods/chats/delete_forum_topic.py b/pyrogram/methods/chats/delete_forum_topic.py index 0fcc8da5..591dd2ba 100644 --- a/pyrogram/methods/chats/delete_forum_topic.py +++ b/pyrogram/methods/chats/delete_forum_topic.py @@ -15,9 +15,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . + import pyrogram from pyrogram import raw -from pyrogram import types from typing import Union diff --git a/pyrogram/methods/chats/edit_forum_topic.py b/pyrogram/methods/chats/edit_forum_topic.py index ceb0aa6d..514aa0ab 100644 --- a/pyrogram/methods/chats/edit_forum_topic.py +++ b/pyrogram/methods/chats/edit_forum_topic.py @@ -15,9 +15,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . + import pyrogram from pyrogram import raw -from pyrogram import types from typing import Union diff --git a/pyrogram/methods/chats/edit_general_topic.py b/pyrogram/methods/chats/edit_general_topic.py index 13459843..dc82264e 100644 --- a/pyrogram/methods/chats/edit_general_topic.py +++ b/pyrogram/methods/chats/edit_general_topic.py @@ -15,9 +15,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . + import pyrogram from pyrogram import raw -from pyrogram import types from typing import Union diff --git a/pyrogram/methods/chats/get_chat_member.py b/pyrogram/methods/chats/get_chat_member.py index 7b86bf51..73f9a952 100644 --- a/pyrogram/methods/chats/get_chat_member.py +++ b/pyrogram/methods/chats/get_chat_member.py @@ -77,8 +77,7 @@ class GetChatMember: else: if member.user.id == user.user_id: return member - else: - raise UserNotParticipant + raise UserNotParticipant elif isinstance(chat, raw.types.InputPeerChannel): r = await self.invoke( raw.functions.channels.GetParticipant( diff --git a/pyrogram/methods/chats/get_forum_topics.py b/pyrogram/methods/chats/get_forum_topics.py index b9aeedf9..84bac3ba 100644 --- a/pyrogram/methods/chats/get_forum_topics.py +++ b/pyrogram/methods/chats/get_forum_topics.py @@ -23,7 +23,6 @@ from typing import Union, Optional, AsyncGenerator import pyrogram from pyrogram import raw from pyrogram import types -from pyrogram import utils log = logging.getLogger(__name__) diff --git a/pyrogram/methods/chats/get_forum_topics_by_id.py b/pyrogram/methods/chats/get_forum_topics_by_id.py index ea2114aa..fe701e0b 100644 --- a/pyrogram/methods/chats/get_forum_topics_by_id.py +++ b/pyrogram/methods/chats/get_forum_topics_by_id.py @@ -23,7 +23,6 @@ from typing import Union, List, Iterable import pyrogram from pyrogram import raw from pyrogram import types -from pyrogram import utils log = logging.getLogger(__name__) @@ -63,7 +62,7 @@ class GetForumTopicsByID: Raises: ValueError: In case of invalid arguments. """ - ids, ids_type = ( + ids, _ = ( (topic_ids, int) if topic_ids else (None, None) ) diff --git a/pyrogram/methods/chats/hide_general_topic.py b/pyrogram/methods/chats/hide_general_topic.py index 901758ca..44c72abb 100644 --- a/pyrogram/methods/chats/hide_general_topic.py +++ b/pyrogram/methods/chats/hide_general_topic.py @@ -17,7 +17,6 @@ # along with Pyrofork. If not, see . import pyrogram from pyrogram import raw -from pyrogram import types from typing import Union diff --git a/pyrogram/methods/chats/reopen_forum_topic.py b/pyrogram/methods/chats/reopen_forum_topic.py index 1b5e6a63..f4b7e9c3 100644 --- a/pyrogram/methods/chats/reopen_forum_topic.py +++ b/pyrogram/methods/chats/reopen_forum_topic.py @@ -15,9 +15,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . + import pyrogram from pyrogram import raw -from pyrogram import types from typing import Union diff --git a/pyrogram/methods/chats/reopen_general_topic.py b/pyrogram/methods/chats/reopen_general_topic.py index a1ba65da..04e6145c 100644 --- a/pyrogram/methods/chats/reopen_general_topic.py +++ b/pyrogram/methods/chats/reopen_general_topic.py @@ -15,9 +15,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . + import pyrogram from pyrogram import raw -from pyrogram import types from typing import Union diff --git a/pyrogram/methods/chats/set_chat_photo.py b/pyrogram/methods/chats/set_chat_photo.py index 07c9b6fb..bb4611cc 100644 --- a/pyrogram/methods/chats/set_chat_photo.py +++ b/pyrogram/methods/chats/set_chat_photo.py @@ -164,5 +164,4 @@ class SetChatPhoto: {i.id: i for i in r.users}, {i.id: i for i in r.chats} ) - else: - return True + return True diff --git a/pyrogram/methods/chats/unhide_general_topic.py b/pyrogram/methods/chats/unhide_general_topic.py index 2bad75ed..d29d9742 100644 --- a/pyrogram/methods/chats/unhide_general_topic.py +++ b/pyrogram/methods/chats/unhide_general_topic.py @@ -15,9 +15,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . + import pyrogram from pyrogram import raw -from pyrogram import types from typing import Union diff --git a/pyrogram/methods/decorators/on_shipping_query.py b/pyrogram/methods/decorators/on_shipping_query.py index 7128a88b..ee53233f 100644 --- a/pyrogram/methods/decorators/on_shipping_query.py +++ b/pyrogram/methods/decorators/on_shipping_query.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Callable, Optional, Union +from typing import Callable import pyrogram from pyrogram.filters import Filter diff --git a/pyrogram/methods/messages/copy_media_group.py b/pyrogram/methods/messages/copy_media_group.py index 485f77f8..98ba58ff 100644 --- a/pyrogram/methods/messages/copy_media_group.py +++ b/pyrogram/methods/messages/copy_media_group.py @@ -180,8 +180,12 @@ class CopyMediaGroup: **await self.parser.parse( captions[i] if isinstance(captions, list) and i < len(captions) and captions[i] else captions if isinstance(captions, str) and i == 0 else - message.caption if message.caption and message.caption != "None" and not type( - captions) is str else "") + message.caption if ( + message.caption + and message.caption != "None" + and not isinstance(captions, str) + ) else "" + ) ) ) diff --git a/pyrogram/methods/messages/get_messages.py b/pyrogram/methods/messages/get_messages.py index 2c143b8b..8ffc8f3e 100644 --- a/pyrogram/methods/messages/get_messages.py +++ b/pyrogram/methods/messages/get_messages.py @@ -104,7 +104,7 @@ class GetMessages: is_iterable = not isinstance(ids, int) ids = list(ids) if is_iterable else [ids] - ids = [ids_type(id=i) for i in ids] + ids = [ids_type(id=i) for i in ids] # pylint: disable=not-callable if replies < 0: replies = (1 << 31) - 1 diff --git a/pyrogram/methods/messages/send_web_page.py b/pyrogram/methods/messages/send_web_page.py index 2050f423..be79610e 100644 --- a/pyrogram/methods/messages/send_web_page.py +++ b/pyrogram/methods/messages/send_web_page.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -import re from datetime import datetime from typing import Union, List, Optional diff --git a/pyrogram/methods/payments/convert_gift.py b/pyrogram/methods/payments/convert_gift.py index 88cb7a12..cdd7b246 100644 --- a/pyrogram/methods/payments/convert_gift.py +++ b/pyrogram/methods/payments/convert_gift.py @@ -17,9 +17,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . - -from typing import Union - import pyrogram from pyrogram import raw diff --git a/pyrogram/methods/users/delete_stories.py b/pyrogram/methods/users/delete_stories.py index 2b2898d0..d249a1f4 100644 --- a/pyrogram/methods/users/delete_stories.py +++ b/pyrogram/methods/users/delete_stories.py @@ -17,11 +17,10 @@ # along with Pyrofork. If not, see . import logging -from typing import Union, List, Iterable +from typing import Union, Iterable import pyrogram from pyrogram import raw -from pyrogram import types log = logging.getLogger(__name__) diff --git a/pyrogram/methods/users/edit_story.py b/pyrogram/methods/users/edit_story.py index 8b78025b..ede2712f 100644 --- a/pyrogram/methods/users/edit_story.py +++ b/pyrogram/methods/users/edit_story.py @@ -222,14 +222,13 @@ class EditStory: if caption: text, entities = self._split(**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)) - ''' - if allowed_chats and len(allowed_chats) > 0: - chats = [int(str(chat_id)[3:]) if str(chat_id).startswith("-100") else chat_id for chat_id in allowed_chats] - privacy_rules.append(raw.types.InputPrivacyValueAllowChatParticipants(chats=chats)) - if denied_chats and len(denied_chats) > 0: - chats = [int(str(chat_id)[3:]) if str(chat_id).startswith("-100") else chat_id for chat_id in denied_chats] - privacy_rules.append(raw.types.InputPrivacyValueDisallowChatParticipants(chats=chats)) - ''' + #if allowed_chats and len(allowed_chats) > 0: + # chats = [int(str(chat_id)[3:]) if str(chat_id).startswith("-100") else chat_id for chat_id in allowed_chats] + # privacy_rules.append(raw.types.InputPrivacyValueAllowChatParticipants(chats=chats)) + #if denied_chats and len(denied_chats) > 0: + # chats = [int(str(chat_id)[3:]) if str(chat_id).startswith("-100") else chat_id for chat_id in denied_chats] + # privacy_rules.append(raw.types.InputPrivacyValueDisallowChatParticipants(chats=chats)) + if allowed_users and len(allowed_users) > 0: users = [await self.resolve_peer(user_id) for user_id in allowed_users] privacy_rules.append(raw.types.InputPrivacyValueAllowUsers(users=users)) diff --git a/pyrogram/methods/users/send_story.py b/pyrogram/methods/users/send_story.py index 8808a66c..fbb299fc 100644 --- a/pyrogram/methods/users/send_story.py +++ b/pyrogram/methods/users/send_story.py @@ -213,14 +213,13 @@ class SendStory: text, entities = self._split(**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)) - ''' - if allowed_chats and len(allowed_chats) > 0: - chats = [await self.resolve_peer(chat_id) for chat_id in allowed_chats] - privacy_rules.append(raw.types.InputPrivacyValueAllowChatParticipants(chats=chats)) - if denied_chats and len(denied_chats) > 0: - chats = [await self.resolve_peer(chat_id) for chat_id in denied_chats] - privacy_rules.append(raw.types.InputPrivacyValueDisallowChatParticipants(chats=chats)) - ''' + #if allowed_chats and len(allowed_chats) > 0: + # chats = [await self.resolve_peer(chat_id) for chat_id in allowed_chats] + # privacy_rules.append(raw.types.InputPrivacyValueAllowChatParticipants(chats=chats)) + #if denied_chats and len(denied_chats) > 0: + # chats = [await self.resolve_peer(chat_id) for chat_id in denied_chats] + # privacy_rules.append(raw.types.InputPrivacyValueDisallowChatParticipants(chats=chats)) + if allowed_users and len(allowed_users) > 0: users = [await self.resolve_peer(user_id) for user_id in allowed_users] privacy_rules.append(raw.types.InputPrivacyValueAllowUsers(users=users)) diff --git a/pyrogram/nav/__init__.py b/pyrogram/nav/__init__.py index 812f6256..7a14129c 100644 --- a/pyrogram/nav/__init__.py +++ b/pyrogram/nav/__init__.py @@ -17,4 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -from .pagination import Pagination \ No newline at end of file +from .pagination import Pagination + +__all__ = [ + "Pagination" +] diff --git a/pyrogram/parser/__init__.py b/pyrogram/parser/__init__.py index 43c6afb1..6e81ca5f 100644 --- a/pyrogram/parser/__init__.py +++ b/pyrogram/parser/__init__.py @@ -18,3 +18,7 @@ # along with Pyrofork. If not, see . from .parser import Parser + +__all__ = [ + "Parser" +] diff --git a/pyrogram/parser/markdown.py b/pyrogram/parser/markdown.py index 9d92a6d2..96c91e29 100644 --- a/pyrogram/parser/markdown.py +++ b/pyrogram/parser/markdown.py @@ -18,7 +18,6 @@ # along with Pyrofork. If not, see . import html -import logging import re from typing import Optional @@ -251,7 +250,7 @@ class Markdown: # Handle multiline blockquotes text_subset = text[s:e] lines = text_subset.splitlines() - for line_num, line in enumerate(lines): + for line_num, _ in enumerate(lines): line_start = s + sum(len(l) + 1 for l in lines[:line_num]) if entity.collapsed: insert_at.append((line_start, i, BLOCKQUOTE_EXPANDABLE_DELIM)) diff --git a/pyrogram/raw/__init__.py b/pyrogram/raw/__init__.py index 9ab7f960..6bb60fc4 100644 --- a/pyrogram/raw/__init__.py +++ b/pyrogram/raw/__init__.py @@ -25,3 +25,11 @@ from .all import objects for k, v in objects.items(): path, name = v.rsplit(".", 1) objects[k] = getattr(import_module(path), name) + +__all__ = [ + "types", + "functions", + "base", + "core", + "objects" +] diff --git a/pyrogram/raw/core/__init__.py b/pyrogram/raw/core/__init__.py index 1aeac260..7cf0aece 100644 --- a/pyrogram/raw/core/__init__.py +++ b/pyrogram/raw/core/__init__.py @@ -30,3 +30,24 @@ from .primitives.int import Int, Long, Int128, Int256 from .primitives.string import String from .primitives.vector import Vector from .tl_object import TLObject + +__all__ = [ + "FutureSalt", + "FutureSalts", + "GzipPacked", + "List", + "Message", + "MsgContainer", + "Bool", + "BoolFalse", + "BoolTrue", + "Bytes", + "Double", + "Int", + "Long", + "Int128", + "Int256", + "String", + "Vector", + "TLObject" +] diff --git a/pyrogram/raw/core/primitives/__init__.py b/pyrogram/raw/core/primitives/__init__.py index 86cc16d2..23ca9679 100644 --- a/pyrogram/raw/core/primitives/__init__.py +++ b/pyrogram/raw/core/primitives/__init__.py @@ -23,3 +23,17 @@ from .double import Double from .int import Int, Long, Int128, Int256 from .string import String from .vector import Vector + +__all__ = [ + "Bool", + "BoolFalse", + "BoolTrue", + "Bytes", + "Double", + "Int", + "Long", + "Int128", + "Int256", + "String", + "Vector" +] diff --git a/pyrogram/session/__init__.py b/pyrogram/session/__init__.py index 67824499..dadfd267 100644 --- a/pyrogram/session/__init__.py +++ b/pyrogram/session/__init__.py @@ -19,3 +19,8 @@ from .auth import Auth from .session import Session + +__all__ = [ + "Auth", + "Session" +] diff --git a/pyrogram/session/internals/__init__.py b/pyrogram/session/internals/__init__.py index 1754586e..86f56250 100644 --- a/pyrogram/session/internals/__init__.py +++ b/pyrogram/session/internals/__init__.py @@ -20,3 +20,9 @@ from .data_center import DataCenter from .msg_factory import MsgFactory from .msg_id import MsgId + +__all__ = [ + "DataCenter", + "MsgFactory", + "MsgId" +] diff --git a/pyrogram/storage/__init__.py b/pyrogram/storage/__init__.py index ba4320c3..93e37231 100644 --- a/pyrogram/storage/__init__.py +++ b/pyrogram/storage/__init__.py @@ -19,10 +19,20 @@ from .file_storage import FileStorage from .memory_storage import MemoryStorage +MONGO_AVAIL = False try: import pymongo except Exception: pass else: + MONGO_AVAIL = True from .mongo_storage import MongoStorage from .storage import Storage + +__all__ = [ + "FileStorage", + "MemoryStorage", + "Storage" +] +if MONGO_AVAIL: + __all__.append("MongoStorage") diff --git a/pyrogram/types/__init__.py b/pyrogram/types/__init__.py index 82460332..e1b90a73 100644 --- a/pyrogram/types/__init__.py +++ b/pyrogram/types/__init__.py @@ -30,3 +30,8 @@ from .update import * from .user_and_chats import * from .payments import * from .pyromod import * + +__all__ = [ + "List", + "Object" +] diff --git a/pyrogram/types/authorization/active_sessions.py b/pyrogram/types/authorization/active_sessions.py index 414e3e70..b372c12a 100644 --- a/pyrogram/types/authorization/active_sessions.py +++ b/pyrogram/types/authorization/active_sessions.py @@ -18,8 +18,7 @@ from typing import List -import pyrogram -from pyrogram import raw, types, utils +from pyrogram import raw, types from ..object import Object diff --git a/pyrogram/types/bots_and_keyboards/game_high_score.py b/pyrogram/types/bots_and_keyboards/game_high_score.py index ea9b9b77..95572632 100644 --- a/pyrogram/types/bots_and_keyboards/game_high_score.py +++ b/pyrogram/types/bots_and_keyboards/game_high_score.py @@ -20,6 +20,7 @@ import pyrogram from pyrogram import raw, utils from pyrogram import types +from typing import Dict from ..object import Object @@ -52,7 +53,11 @@ class GameHighScore(Object): self.position = position @staticmethod - def _parse(client, game_high_score: raw.types.HighScore, users: dict) -> "GameHighScore": + def _parse( + client, + game_high_score: raw.types.HighScore, + users: Dict[int, "raw.types.User"] + ) -> "GameHighScore": users = {i.id: i for i in users} return GameHighScore( @@ -63,7 +68,11 @@ class GameHighScore(Object): ) @staticmethod - def _parse_action(client, service: raw.types.MessageService, users: dict): + def _parse_action( + client, + service: raw.types.MessageService, + users: Dict[int, "raw.types.User"] + ) -> "GameHighScore": return GameHighScore( user=types.User._parse(client, users[utils.get_raw_peer_id(service.from_id or service.peer_id)]), score=service.action.score, diff --git a/pyrogram/types/bots_and_keyboards/requested_chats.py b/pyrogram/types/bots_and_keyboards/requested_chats.py index 554edd81..a0275735 100644 --- a/pyrogram/types/bots_and_keyboards/requested_chats.py +++ b/pyrogram/types/bots_and_keyboards/requested_chats.py @@ -17,7 +17,7 @@ # along with Pyrofork. If not, see . from ..object import Object -from pyrogram import enums, raw, types +from pyrogram import raw, types from typing import Union, List class RequestedChats(Object): diff --git a/pyrogram/types/bots_and_keyboards/requested_user.py b/pyrogram/types/bots_and_keyboards/requested_user.py index 6b4eb5d8..c5789488 100644 --- a/pyrogram/types/bots_and_keyboards/requested_user.py +++ b/pyrogram/types/bots_and_keyboards/requested_user.py @@ -17,7 +17,7 @@ # along with Pyrofork. If not, see . from ..object import Object -from pyrogram import enums, raw, types +from pyrogram import raw, types from typing import Union class RequestedUser(Object): diff --git a/pyrogram/types/business/shipping_option.py b/pyrogram/types/business/shipping_option.py index 81f64124..f0b4e5c6 100644 --- a/pyrogram/types/business/shipping_option.py +++ b/pyrogram/types/business/shipping_option.py @@ -17,9 +17,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import List - -import pyrogram from pyrogram import raw, types from ..object import Object diff --git a/pyrogram/types/business/shipping_query.py b/pyrogram/types/business/shipping_query.py index ca254a23..71a1192e 100644 --- a/pyrogram/types/business/shipping_query.py +++ b/pyrogram/types/business/shipping_query.py @@ -19,6 +19,7 @@ import pyrogram from pyrogram import raw, types +from typing import Dict from ..object import Object from ..update import Update @@ -62,7 +63,7 @@ class ShippingQuery(Object, Update): async def _parse( client: "pyrogram.Client", shipping_query: "raw.types.UpdateBotShippingQuery", - users: dict + users: Dict[int, "raw.types.User"] ) -> "types.PreCheckoutQuery": # Try to decode pre-checkout query payload into string. If that fails, fallback to bytes instead of decoding by # ignoring/replacing errors, this way, button clicks will still work. diff --git a/pyrogram/types/inline_mode/inline_query.py b/pyrogram/types/inline_mode/inline_query.py index a55d7933..0c9c3fdf 100644 --- a/pyrogram/types/inline_mode/inline_query.py +++ b/pyrogram/types/inline_mode/inline_query.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -from typing import List, Match +from typing import List, Match, Dict import pyrogram from pyrogram import raw @@ -78,7 +78,11 @@ class InlineQuery(Object, Update): self.matches = matches @staticmethod - def _parse(client, inline_query: raw.types.UpdateBotInlineQuery, users: dict) -> "InlineQuery": + def _parse( + client, + inline_query: raw.types.UpdateBotInlineQuery, + users: Dict[int, "raw.types.User"] + ) -> "InlineQuery": peer_type = inline_query.peer_type chat_type = None diff --git a/pyrogram/types/messages_and_media/alternative_video.py b/pyrogram/types/messages_and_media/alternative_video.py index 921830a7..63881021 100644 --- a/pyrogram/types/messages_and_media/alternative_video.py +++ b/pyrogram/types/messages_and_media/alternative_video.py @@ -22,7 +22,7 @@ from typing import List import pyrogram from pyrogram import raw, utils from pyrogram import types -from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType, ThumbnailSource +from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType from ..object import Object diff --git a/pyrogram/types/messages_and_media/exported_story_link.py b/pyrogram/types/messages_and_media/exported_story_link.py index 15287904..3698c5e9 100644 --- a/pyrogram/types/messages_and_media/exported_story_link.py +++ b/pyrogram/types/messages_and_media/exported_story_link.py @@ -17,7 +17,6 @@ # along with Pyrofork. If not, see . from pyrogram import raw -from typing import List from ..object import Object class ExportedStoryLink(Object): diff --git a/pyrogram/types/messages_and_media/giveaway.py b/pyrogram/types/messages_and_media/giveaway.py index a1a36ccd..517d87d4 100644 --- a/pyrogram/types/messages_and_media/giveaway.py +++ b/pyrogram/types/messages_and_media/giveaway.py @@ -16,12 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -import asyncio import pyrogram from datetime import datetime from pyrogram import raw, types, utils -from pyrogram.errors import FloodWait from ..object import Object from typing import List, Dict diff --git a/pyrogram/types/messages_and_media/media_area_coordinates.py b/pyrogram/types/messages_and_media/media_area_coordinates.py index c20935ef..8c1e8e1e 100644 --- a/pyrogram/types/messages_and_media/media_area_coordinates.py +++ b/pyrogram/types/messages_and_media/media_area_coordinates.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -from pyrogram import types, raw +from pyrogram import raw from ..object import Object diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index bc3a2fd2..d5cb3f94 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -20,7 +20,7 @@ import logging from datetime import datetime from functools import partial -from typing import List, Match, Union, BinaryIO, Optional, Callable +from typing import List, Match, Union, BinaryIO, Optional, Callable, Dict import pyrogram from pyrogram import enums, raw, types, utils @@ -690,9 +690,9 @@ class Message(Object, Update): async def _parse( client: "pyrogram.Client", message: raw.base.Message, - users: dict, - chats: dict, - topics: dict = None, + users: Dict[int, "raw.types.User"], + chats: Dict[int, "raw.types.Chat"], + topics: Dict[int, "raw.types.ForumTopic"] = None, is_scheduled: bool = False, business_connection_id: str = None, replies: int = 1 diff --git a/pyrogram/types/messages_and_media/message_entity.py b/pyrogram/types/messages_and_media/message_entity.py index 62a3c61b..832e6996 100644 --- a/pyrogram/types/messages_and_media/message_entity.py +++ b/pyrogram/types/messages_and_media/message_entity.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -from typing import Optional +from typing import Optional, Dict import pyrogram from pyrogram import raw, enums @@ -82,7 +82,11 @@ class MessageEntity(Object): self.collapsed = collapsed @staticmethod - def _parse(client, entity: "raw.base.MessageEntity", users: dict) -> Optional["MessageEntity"]: + def _parse( + client, + entity: "raw.base.MessageEntity", + users: Dict[int, "raw.types.User"] = None + ) -> Optional["MessageEntity"]: # Special case for InputMessageEntityMentionName -> MessageEntityType.TEXT_MENTION # This happens in case of UpdateShortSentMessage inside send_message() where entities are parsed from the input if isinstance(entity, raw.types.InputMessageEntityMentionName): diff --git a/pyrogram/types/messages_and_media/read_participant.py b/pyrogram/types/messages_and_media/read_participant.py index 4b772396..467d0011 100644 --- a/pyrogram/types/messages_and_media/read_participant.py +++ b/pyrogram/types/messages_and_media/read_participant.py @@ -17,7 +17,7 @@ # along with PyroFork. If not, see . import pyrogram -from pyrogram import raw, types, utils +from pyrogram import raw, utils from datetime import datetime from ..object import Object diff --git a/pyrogram/types/messages_and_media/sticker.py b/pyrogram/types/messages_and_media/sticker.py index eab0987f..d8f64e94 100644 --- a/pyrogram/types/messages_and_media/sticker.py +++ b/pyrogram/types/messages_and_media/sticker.py @@ -145,7 +145,7 @@ class Sticker(Object): Sticker.cache[(set_id, set_access_hash)] = name if len(Sticker.cache) > 250: - for i in range(50): + for _ in range(50): Sticker.cache.pop(next(iter(Sticker.cache))) return name diff --git a/pyrogram/types/messages_and_media/stickerset.py b/pyrogram/types/messages_and_media/stickerset.py index aa56165b..553cccee 100644 --- a/pyrogram/types/messages_and_media/stickerset.py +++ b/pyrogram/types/messages_and_media/stickerset.py @@ -16,11 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -from typing import List, Optional, Union -import pyrogram from pyrogram import raw -from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType, ThumbnailSource from ..object import Object diff --git a/pyrogram/types/messages_and_media/story.py b/pyrogram/types/messages_and_media/story.py index 91bfbfb4..d37b55cb 100644 --- a/pyrogram/types/messages_and_media/story.py +++ b/pyrogram/types/messages_and_media/story.py @@ -193,6 +193,7 @@ class Story(Object, Update): animation = None photo = None video = None + media_type = None chat = None from_user = None sender_chat = None @@ -268,14 +269,13 @@ class Story(Object, Update): elif isinstance(priv, raw.types.PrivacyValueDisallowContacts): privacy = enums.StoryPrivacy.NO_CONTACTS - ''' - if allowed_chats and len(allowed_chats) > 0: - chats = [int(str(chat_id)[3:]) if str(chat_id).startswith("-100") else chat_id for chat_id in allowed_chats] - privacy_rules.append(raw.types.InputPrivacyValueAllowChatParticipants(chats=chats)) - if denied_chats and len(denied_chats) > 0: - chats = [int(str(chat_id)[3:]) if str(chat_id).startswith("-100") else chat_id for chat_id in denied_chats] - privacy_rules.append(raw.types.InputPrivacyValueDisallowChatParticipants(chats=chats)) - ''' + #if allowed_chats and len(allowed_chats) > 0: + # chats = [int(str(chat_id)[3:]) if str(chat_id).startswith("-100") else chat_id for chat_id in allowed_chats] + # privacy_rules.append(raw.types.InputPrivacyValueAllowChatParticipants(chats=chats)) + #if denied_chats and len(denied_chats) > 0: + # chats = [int(str(chat_id)[3:]) if str(chat_id).startswith("-100") else chat_id for chat_id in denied_chats] + # privacy_rules.append(raw.types.InputPrivacyValueDisallowChatParticipants(chats=chats)) + if isinstance(priv, raw.types.PrivacyValueAllowUsers): allowed_users = priv.users if isinstance(priv, raw.types.PrivacyValueDisallowUsers): diff --git a/pyrogram/types/messages_and_media/transcribed_audio.py b/pyrogram/types/messages_and_media/transcribed_audio.py index 0351ff1a..1231f319 100644 --- a/pyrogram/types/messages_and_media/transcribed_audio.py +++ b/pyrogram/types/messages_and_media/transcribed_audio.py @@ -57,7 +57,7 @@ class TranscribedAudio(Object): self.trial_remains_until_date = trial_remains_until_date @staticmethod - def _parse(transcribe_result: "raw.types.messages.TranscribedAudio") -> "TranscribeAudio": + def _parse(transcribe_result: "raw.types.messages.TranscribedAudio") -> "TranscribedAudio": return TranscribedAudio( transcription_id=transcribe_result.transcription_id, text=transcribe_result.text, diff --git a/pyrogram/types/messages_and_media/translated_text.py b/pyrogram/types/messages_and_media/translated_text.py index 7215463d..5fb01a32 100644 --- a/pyrogram/types/messages_and_media/translated_text.py +++ b/pyrogram/types/messages_and_media/translated_text.py @@ -19,7 +19,6 @@ from typing import List -import pyrogram from pyrogram import raw, types from ..object import Object diff --git a/pyrogram/types/messages_and_media/video.py b/pyrogram/types/messages_and_media/video.py index 1b6861da..f5bf4f55 100644 --- a/pyrogram/types/messages_and_media/video.py +++ b/pyrogram/types/messages_and_media/video.py @@ -22,7 +22,7 @@ from typing import List import pyrogram from pyrogram import raw, types, utils -from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType, ThumbnailSource +from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType from ..object import Object diff --git a/pyrogram/types/messages_and_media/web_page_empty.py b/pyrogram/types/messages_and_media/web_page_empty.py index 03837390..995d317c 100644 --- a/pyrogram/types/messages_and_media/web_page_empty.py +++ b/pyrogram/types/messages_and_media/web_page_empty.py @@ -17,9 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -import pyrogram from pyrogram import raw -from pyrogram import types from ..object import Object diff --git a/pyrogram/types/messages_and_media/web_page_preview.py b/pyrogram/types/messages_and_media/web_page_preview.py index adf1d061..c807b045 100644 --- a/pyrogram/types/messages_and_media/web_page_preview.py +++ b/pyrogram/types/messages_and_media/web_page_preview.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -import pyrogram from pyrogram import raw from pyrogram import types from ..object import Object diff --git a/pyrogram/types/payments/gift.py b/pyrogram/types/payments/gift.py index 48ad6cb0..348a937d 100644 --- a/pyrogram/types/payments/gift.py +++ b/pyrogram/types/payments/gift.py @@ -18,7 +18,7 @@ # along with Pyrofork. If not, see . from datetime import datetime -from typing import List, Optional, Union +from typing import List, Optional, Union, Dict import pyrogram from pyrogram import raw, types, utils @@ -226,7 +226,7 @@ class Gift(Object): self.raw = raw @staticmethod - async def _parse(client, gift, users={}, chats={}): + async def _parse(client, gift, users=None, chats=None): if isinstance(gift, raw.types.StarGift): return await Gift._parse_regular(client, gift) elif isinstance(gift, raw.types.StarGiftUnique): @@ -263,8 +263,8 @@ class Gift(Object): async def _parse_unique( client, star_gift: "raw.types.StarGiftUnique", - users: dict = {}, - chats: dict = {} + users: Dict[int, "raw.types.User"] = None, + chats: Dict[int, "raw.types.Chat"] = None ) -> "Gift": owner_id = utils.get_raw_peer_id(getattr(star_gift, "owner_id", None)) return Gift( @@ -273,7 +273,7 @@ class Gift(Object): title=star_gift.title, collectible_id=star_gift.num, attributes=types.List( - [await types.GiftAttribute._parse(client, attr, users, chats) for attr in star_gift.attributes] + [await types.GiftAttribute._parse(client, attr, users) for attr in star_gift.attributes] ) or None, available_amount=getattr(star_gift, "availability_issued", None), total_amount=getattr(star_gift, "availability_total", None), @@ -289,8 +289,8 @@ class Gift(Object): async def _parse_saved( client, saved_gift: "raw.types.SavedStarGift", - users: dict = {}, - chats: dict = {} + users: Dict[int, "raw.types.User"] = None, + chats: Dict[int, "raw.types.Chat"] = None ) -> "Gift": caption, caption_entities = ( utils.parse_text_with_entities( @@ -324,8 +324,8 @@ class Gift(Object): async def _parse_action( client, message: "raw.base.Message", - users: dict = {}, - chats: dict = {} + users: Dict[int, "raw.types.User"] = None, + chats: Dict[int, "raw.types.Chat"] = None ) -> "Gift": action = message.action # type: raw.types.MessageActionStarGift diff --git a/pyrogram/types/payments/gift_attribute.py b/pyrogram/types/payments/gift_attribute.py index 79d973dc..39226796 100644 --- a/pyrogram/types/payments/gift_attribute.py +++ b/pyrogram/types/payments/gift_attribute.py @@ -18,7 +18,7 @@ # along with Pyrofork. If not, see . from datetime import datetime -from typing import List, Optional +from typing import List, Optional, Dict import pyrogram from pyrogram import enums, raw, types, utils @@ -119,8 +119,7 @@ class GiftAttribute(Object): async def _parse( client, attr: "raw.base.StarGiftAttribute", - users: dict, - chats: dict + users: Dict[int, "raw.types.User"] ) -> "GiftAttribute": caption = None caption_entities = None diff --git a/pyrogram/types/payments/gift_code.py b/pyrogram/types/payments/gift_code.py index 471a2858..bd54b145 100644 --- a/pyrogram/types/payments/gift_code.py +++ b/pyrogram/types/payments/gift_code.py @@ -19,7 +19,8 @@ import pyrogram from ..object import Object -from pyrogram import types, utils +from pyrogram import raw, types, utils +from typing import Dict class GiftCode(Object): @@ -78,7 +79,11 @@ class GiftCode(Object): self.crypto_amount = crypto_amount @staticmethod - def _parse(client: "pyrogram.Client", gift_code: "types.GiftCode", chats: dict,) -> "GiftCode": + def _parse( + client: "pyrogram.Client", + gift_code: "types.GiftCode", + chats: Dict[int, "raw.types.Chat"] + ) -> "GiftCode": boosted_chat = None boosted_chat_raw = chats.get(utils.get_raw_peer_id(gift_code.boost_peer), None) if boosted_chat_raw: diff --git a/pyrogram/types/payments/gifted_premium.py b/pyrogram/types/payments/gifted_premium.py index eb093c75..deb536c3 100644 --- a/pyrogram/types/payments/gifted_premium.py +++ b/pyrogram/types/payments/gifted_premium.py @@ -17,9 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -from random import choice - -from pyrogram import raw, types +from pyrogram import raw from ..object import Object diff --git a/pyrogram/types/payments/input_stars_transaction.py b/pyrogram/types/payments/input_stars_transaction.py index 156d2c45..77264c8c 100644 --- a/pyrogram/types/payments/input_stars_transaction.py +++ b/pyrogram/types/payments/input_stars_transaction.py @@ -16,8 +16,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -import pyrogram - from pyrogram import raw from ..object import Object diff --git a/pyrogram/types/payments/invoice.py b/pyrogram/types/payments/invoice.py index 4b4e7038..50b0494e 100644 --- a/pyrogram/types/payments/invoice.py +++ b/pyrogram/types/payments/invoice.py @@ -16,9 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -import pyrogram - -from pyrogram import raw, types, utils +from pyrogram import raw from ..object import Object diff --git a/pyrogram/types/payments/payment_form.py b/pyrogram/types/payments/payment_form.py index 0d6f0ef2..285a4860 100644 --- a/pyrogram/types/payments/payment_form.py +++ b/pyrogram/types/payments/payment_form.py @@ -107,7 +107,7 @@ class PaymentForm(Object): bot=types.User._parse(client, users.get(payment_form.bot_id)), title=payment_form.title, description=payment_form.description, - invoice=types.Invoice._parse(client, payment_form.invoice), + invoice=types.Invoice._parse(payment_form.invoice), provider=types.User._parse(client, users.get(getattr(payment_form, "provider_id", None))), url=getattr(payment_form, "url", None), can_save_credentials=getattr(payment_form, "can_save_credentials", None), diff --git a/pyrogram/types/payments/payment_info.py b/pyrogram/types/payments/payment_info.py index aaf499f1..ca8de244 100644 --- a/pyrogram/types/payments/payment_info.py +++ b/pyrogram/types/payments/payment_info.py @@ -17,6 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . +from pyrogram import types + from ..object import Object diff --git a/pyrogram/types/payments/stars_transaction.py b/pyrogram/types/payments/stars_transaction.py index b2619403..5e9105b0 100644 --- a/pyrogram/types/payments/stars_transaction.py +++ b/pyrogram/types/payments/stars_transaction.py @@ -18,6 +18,7 @@ from datetime import datetime from pyrogram import raw, types, utils +from typing import Dict from ..object import Object class StarsTransaction(Object): @@ -100,7 +101,7 @@ class StarsTransaction(Object): def _parse( client, transaction: "raw.types.StarsTransaction", - users: dict + users: Dict[int, "raw.types.User"] ) -> "StarsTransaction": chat_id = utils.get_raw_peer_id(transaction.peer.peer) chat = types.User._parse(client, users.get(chat_id, None)) diff --git a/pyrogram/types/payments/successful_payment.py b/pyrogram/types/payments/successful_payment.py index b71bedd7..8b0a1cb2 100644 --- a/pyrogram/types/payments/successful_payment.py +++ b/pyrogram/types/payments/successful_payment.py @@ -17,6 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . +import pyrogram + from pyrogram import raw from pyrogram import types from ..object import Object diff --git a/pyrogram/types/user_and_chats/birthday.py b/pyrogram/types/user_and_chats/birthday.py index 18b7b567..e95a2d5a 100644 --- a/pyrogram/types/user_and_chats/birthday.py +++ b/pyrogram/types/user_and_chats/birthday.py @@ -16,10 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -from typing import Optional, Union - from pyrogram import raw -from pyrogram import enums from ..object import Object diff --git a/pyrogram/types/user_and_chats/business_info.py b/pyrogram/types/user_and_chats/business_info.py index c79e6e63..ccd6fcd9 100644 --- a/pyrogram/types/user_and_chats/business_info.py +++ b/pyrogram/types/user_and_chats/business_info.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -from typing import Optional +from typing import Optional, Dict from pyrogram import types, raw from ..object import Object @@ -62,7 +62,7 @@ class BusinessInfo(Object): def _parse( client, user: "raw.types.UserFull" = None, - users: dict = None + users: Dict[int, "raw.types.User"] = None ) -> Optional["BusinessInfo"]: working_hours = getattr(user, "business_work_hours", None) location = getattr(user, "business_location", None) diff --git a/pyrogram/types/user_and_chats/business_message.py b/pyrogram/types/user_and_chats/business_message.py index dfcead79..fad3cd61 100644 --- a/pyrogram/types/user_and_chats/business_message.py +++ b/pyrogram/types/user_and_chats/business_message.py @@ -17,7 +17,7 @@ # along with Pyrofork. If not, see . from datetime import datetime -from typing import Optional, Union, List +from typing import Optional, Union, List, Dict from pyrogram import types, enums, raw, utils from ..object import Object @@ -83,7 +83,7 @@ class BusinessMessage(Object): def _parse( client, message: Union["raw.types.BusinessGreetingMessage", "raw.types.BusinessAwayMessage"] = None, - users: dict = None + users: Dict[int, "raw.types.User"] = None ) -> Optional["BusinessMessage"]: if not message: return None diff --git a/pyrogram/types/user_and_chats/business_recipients.py b/pyrogram/types/user_and_chats/business_recipients.py index bf2fae18..7a36adb6 100644 --- a/pyrogram/types/user_and_chats/business_recipients.py +++ b/pyrogram/types/user_and_chats/business_recipients.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -from typing import List +from typing import List, Dict from pyrogram import types, raw from ..object import Object @@ -66,7 +66,7 @@ class BusinessRecipients(Object): def _parse( client, recipients: "raw.types.BusinessRecipients", - users: dict = None + users: Dict[int, "raw.types.User"] = None ) -> "BusinessRecipients": return BusinessRecipients( existing_chats=getattr(recipients, "existing_chats", None), diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 4df2bbab..776a8809 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -18,7 +18,7 @@ # along with Pyrofork. If not, see . from datetime import datetime -from typing import Union, List, Optional, AsyncGenerator, BinaryIO +from typing import Union, List, Optional, AsyncGenerator, BinaryIO, Dict import pyrogram from pyrogram import raw, enums @@ -434,8 +434,8 @@ class Chat(Object): def _parse( client, message: Union[raw.types.Message, raw.types.MessageService], - users: dict, - chats: dict, + users: Dict[int, "raw.types.User"], + chats: Dict[int, "raw.types.Chat"], is_chat: bool ) -> "Chat": from_id = utils.get_raw_peer_id(message.from_id) @@ -451,7 +451,16 @@ class Chat(Object): return Chat._parse_channel_chat(client, chats[chat_id]) @staticmethod - def _parse_dialog(client, peer, users: dict, chats: dict): + def _parse_dialog( + client, + peer: Union[ + raw.types.PeerUser, + raw.types.PeerChat, + raw.types.PeerChannel + ], + users: Dict[int, "raw.types.User"], + chats: Dict[int, "raw.types.Chat"] + ) -> "Chat": if isinstance(peer, raw.types.PeerUser): return Chat._parse_user_chat(client, users[peer.user_id]) elif isinstance(peer, raw.types.PeerChat): diff --git a/pyrogram/types/user_and_chats/forum_topic_deleted.py b/pyrogram/types/user_and_chats/forum_topic_deleted.py index c7402ad4..3d157347 100644 --- a/pyrogram/types/user_and_chats/forum_topic_deleted.py +++ b/pyrogram/types/user_and_chats/forum_topic_deleted.py @@ -16,8 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -from pyrogram import raw, types -from typing import Union +from pyrogram import raw from ..object import Object