From 777f774c3064e588aa40864649863667cd1a706d Mon Sep 17 00:00:00 2001 From: Hitalo Date: Mon, 4 Dec 2023 19:25:57 -0300 Subject: [PATCH 1/5] feat: update Python version to 3.9 and typehints --- .pre-commit-config.yaml | 2 +- compiler/api/compiler.py | 4 +- hydrogram/client.py | 5 +- hydrogram/errors/rpc_error.py | 4 +- hydrogram/file_id.py | 6 +-- hydrogram/filters.py | 11 ++-- .../handlers/deleted_messages_handler.py | 4 +- hydrogram/methods/bots/answer_inline_query.py | 2 +- hydrogram/methods/bots/get_bot_commands.py | 3 +- .../methods/bots/get_game_high_scores.py | 4 +- hydrogram/methods/bots/set_bot_commands.py | 3 +- hydrogram/methods/chats/add_chat_members.py | 4 +- hydrogram/methods/chats/archive_chats.py | 4 +- hydrogram/methods/chats/create_group.py | 4 +- hydrogram/methods/chats/get_chat_event_log.py | 5 +- hydrogram/methods/chats/get_chat_members.py | 3 +- hydrogram/methods/chats/get_dialogs.py | 3 +- hydrogram/methods/chats/get_forum_topics.py | 3 +- .../methods/chats/get_forum_topics_by_id.py | 5 +- hydrogram/methods/chats/get_nearby_chats.py | 3 +- hydrogram/methods/chats/get_send_as_chats.py | 4 +- hydrogram/methods/chats/unarchive_chats.py | 4 +- hydrogram/methods/contacts/delete_contacts.py | 6 +-- hydrogram/methods/contacts/get_contacts.py | 3 +- hydrogram/methods/contacts/import_contacts.py | 3 +- .../get_chat_admin_invite_links.py | 3 +- .../get_chat_invite_link_joiners.py | 3 +- .../invite_links/get_chat_join_requests.py | 3 +- .../methods/messages/copy_media_group.py | 6 +-- hydrogram/methods/messages/copy_message.py | 4 +- hydrogram/methods/messages/delete_messages.py | 3 +- .../methods/messages/edit_message_caption.py | 4 +- .../methods/messages/edit_message_text.py | 4 +- .../methods/messages/forward_messages.py | 5 +- .../methods/messages/get_chat_history.py | 3 +- .../messages/get_custom_emoji_stickers.py | 5 +- .../messages/get_discussion_replies.py | 3 +- hydrogram/methods/messages/get_media_group.py | 4 +- hydrogram/methods/messages/get_messages.py | 5 +- hydrogram/methods/messages/search_global.py | 3 +- hydrogram/methods/messages/search_messages.py | 5 +- hydrogram/methods/messages/send_animation.py | 4 +- hydrogram/methods/messages/send_audio.py | 4 +- .../methods/messages/send_cached_media.py | 4 +- hydrogram/methods/messages/send_document.py | 4 +- .../methods/messages/send_media_group.py | 6 +-- hydrogram/methods/messages/send_message.py | 4 +- hydrogram/methods/messages/send_photo.py | 4 +- hydrogram/methods/messages/send_poll.py | 6 +-- hydrogram/methods/messages/send_video.py | 4 +- hydrogram/methods/messages/send_voice.py | 4 +- hydrogram/methods/messages/vote_poll.py | 4 +- .../methods/users/delete_profile_photos.py | 4 +- hydrogram/methods/users/get_chat_photos.py | 3 +- hydrogram/methods/users/get_common_chats.py | 4 +- .../users/get_default_emoji_statuses.py | 3 +- hydrogram/methods/users/get_users.py | 5 +- hydrogram/methods/utilities/compose.py | 3 +- hydrogram/raw/core/future_salts.py | 4 +- hydrogram/raw/core/list.py | 3 +- hydrogram/raw/core/msg_container.py | 4 +- hydrogram/raw/core/tl_object.py | 6 +-- hydrogram/session/internals/data_center.py | 4 +- hydrogram/storage/base.py | 3 +- hydrogram/storage/sqlite_storage.py | 4 +- .../types/authorization/terms_of_service.py | 3 +- .../bots_and_keyboards/callback_query.py | 5 +- .../inline_keyboard_markup.py | 3 +- .../reply_keyboard_markup.py | 4 +- hydrogram/types/inline_mode/inline_query.py | 7 +-- .../inline_query_result_animation.py | 4 +- .../inline_mode/inline_query_result_audio.py | 4 +- .../inline_query_result_cached_animation.py | 4 +- .../inline_query_result_cached_audio.py | 4 +- .../inline_query_result_cached_document.py | 4 +- .../inline_query_result_cached_photo.py | 4 +- .../inline_query_result_cached_video.py | 4 +- .../inline_query_result_cached_voice.py | 4 +- .../inline_query_result_document.py | 4 +- .../inline_mode/inline_query_result_photo.py | 4 +- .../inline_mode/inline_query_result_video.py | 4 +- .../inline_mode/inline_query_result_voice.py | 4 +- hydrogram/types/input_media/input_media.py | 4 +- .../input_media/input_media_animation.py | 4 +- .../types/input_media/input_media_audio.py | 4 +- .../types/input_media/input_media_document.py | 4 +- .../types/input_media/input_media_photo.py | 4 +- .../types/input_media/input_media_video.py | 4 +- .../input_text_message_content.py | 4 +- .../types/messages_and_media/animation.py | 4 +- hydrogram/types/messages_and_media/audio.py | 4 +- .../types/messages_and_media/document.py | 4 +- hydrogram/types/messages_and_media/message.py | 51 ++++++++++--------- .../messages_and_media/message_reactions.py | 4 +- hydrogram/types/messages_and_media/photo.py | 6 +-- hydrogram/types/messages_and_media/poll.py | 8 +-- hydrogram/types/messages_and_media/sticker.py | 8 +-- .../types/messages_and_media/thumbnail.py | 4 +- hydrogram/types/messages_and_media/video.py | 4 +- .../types/messages_and_media/video_note.py | 4 +- hydrogram/types/user_and_chats/chat.py | 9 ++-- .../chat_admin_with_invite_links.py | 4 +- hydrogram/types/user_and_chats/chat_event.py | 6 +-- .../types/user_and_chats/chat_invite_link.py | 4 +- .../types/user_and_chats/chat_join_request.py | 6 +-- hydrogram/types/user_and_chats/chat_joiner.py | 4 +- hydrogram/types/user_and_chats/chat_member.py | 6 +-- .../user_and_chats/chat_member_updated.py | 6 +-- .../types/user_and_chats/chat_preview.py | 4 +- .../types/user_and_chats/chat_reactions.py | 4 +- hydrogram/types/user_and_chats/user.py | 6 +-- .../video_chat_members_invited.py | 5 +- hydrogram/utils.py | 10 ++-- pyproject.toml | 10 ++-- 114 files changed, 276 insertions(+), 270 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 010dc4197..f99f2d14e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: - id: check-yaml - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.4 + rev: v0.1.6 hooks: - id: ruff-format - id: ruff diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 80d69c592..c6a9d4c6d 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -23,7 +23,7 @@ import shutil from functools import partial from pathlib import Path -from typing import List, NamedTuple, Tuple +from typing import NamedTuple # from autoflake import fix_code # from black import format_str, FileMode @@ -84,7 +84,7 @@ class Combinator(NamedTuple): name: str id: str has_flags: bool - args: List[Tuple[str, str]] + args: list[tuple[str, str]] qualtype: str typespace: str type: str diff --git a/hydrogram/client.py b/hydrogram/client.py index 1b5be4d61..708eee885 100644 --- a/hydrogram/client.py +++ b/hydrogram/client.py @@ -27,6 +27,7 @@ import re import shutil import sys +from collections.abc import AsyncGenerator from concurrent.futures.thread import ThreadPoolExecutor from datetime import datetime, timedelta from hashlib import sha256 @@ -34,7 +35,7 @@ from io import BytesIO, StringIO from mimetypes import MimeTypes from pathlib import Path -from typing import AsyncGenerator, Callable, List, Optional, Union +from typing import Callable, Optional, Union import hydrogram from hydrogram import __license__, __version__, enums, raw, utils @@ -499,7 +500,7 @@ def set_parse_mode(self, parse_mode: Optional["enums.ParseMode"]): self.parse_mode = parse_mode async def fetch_peers( - self, peers: List[Union[raw.types.User, raw.types.Chat, raw.types.Channel]] + self, peers: list[Union[raw.types.User, raw.types.Chat, raw.types.Channel]] ) -> bool: is_min = False parsed_peers = [] diff --git a/hydrogram/errors/rpc_error.py b/hydrogram/errors/rpc_error.py index 62e19b98e..b510a0075 100644 --- a/hydrogram/errors/rpc_error.py +++ b/hydrogram/errors/rpc_error.py @@ -21,7 +21,7 @@ from datetime import datetime from importlib import import_module from pathlib import Path -from typing import Optional, Type, Union +from typing import Optional, Union from hydrogram import raw from hydrogram.raw.core import TLObject @@ -62,7 +62,7 @@ def __init__( f.write(f"{datetime.now()}\t{value}\t{rpc_name}\n") @staticmethod - def raise_it(rpc_error: "raw.types.RpcError", rpc_type: Type[TLObject]): + def raise_it(rpc_error: "raw.types.RpcError", rpc_type: type[TLObject]): error_code = rpc_error.error_code is_signed = error_code < 0 error_message = rpc_error.error_message diff --git a/hydrogram/file_id.py b/hydrogram/file_id.py index 027b20374..a89144e1e 100644 --- a/hydrogram/file_id.py +++ b/hydrogram/file_id.py @@ -22,7 +22,7 @@ import struct from enum import IntEnum from io import BytesIO -from typing import List, Optional +from typing import Optional from hydrogram.raw.core import Bytes, String @@ -65,7 +65,7 @@ def rle_encode(s: bytes) -> bytes: Returns: ``bytes``: The encoded bytes """ - r: List[int] = [] + r: list[int] = [] n: int = 0 for b in s: @@ -94,7 +94,7 @@ def rle_decode(s: bytes) -> bytes: Returns: ``bytes``: The decoded bytes """ - r: List[int] = [] + r: list[int] = [] z: bool = False for b in s: diff --git a/hydrogram/filters.py b/hydrogram/filters.py index 0504d31e0..87b83ad37 100644 --- a/hydrogram/filters.py +++ b/hydrogram/filters.py @@ -19,7 +19,8 @@ import inspect import re -from typing import Callable, List, Optional, Pattern, Union +from re import Pattern +from typing import Callable, Optional, Union import hydrogram from hydrogram import enums @@ -787,8 +788,8 @@ async def linked_channel_filter(_, __, m: Message): # region command_filter def command( - commands: Union[str, List[str]], - prefixes: Union[str, List[str]] = "/", + commands: Union[str, list[str]], + prefixes: Union[str, list[str]] = "/", case_sensitive: bool = False, ): """Filter commands, i.e.: text messages starting with "/" or any other custom prefix. @@ -928,7 +929,7 @@ class user(Filter, set): # noqa: N801 Defaults to None (no users). """ - def __init__(self, users: Optional[Union[int, str, List[Union[int, str]]]] = None): + def __init__(self, users: Optional[Union[int, str, list[Union[int, str]]]] = None): users = [] if users is None else users if isinstance(users, list) else [users] super().__init__( @@ -957,7 +958,7 @@ class chat(Filter, set): # noqa: N801 Defaults to None (no chats). """ - def __init__(self, chats: Optional[Union[int, str, List[Union[int, str]]]] = None): + def __init__(self, chats: Optional[Union[int, str, list[Union[int, str]]]] = None): chats = [] if chats is None else chats if isinstance(chats, list) else [chats] super().__init__( diff --git a/hydrogram/handlers/deleted_messages_handler.py b/hydrogram/handlers/deleted_messages_handler.py index 3dfc579ad..90936d447 100644 --- a/hydrogram/handlers/deleted_messages_handler.py +++ b/hydrogram/handlers/deleted_messages_handler.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import Callable, List +from typing import Callable import hydrogram from hydrogram.filters import Filter @@ -53,7 +53,7 @@ class DeletedMessagesHandler(Handler): def __init__(self, callback: Callable, filters: Filter = None): super().__init__(callback, filters) - async def check(self, client: "hydrogram.Client", messages: List[Message]): + async def check(self, client: "hydrogram.Client", messages: list[Message]): # Every message should be checked, if at least one matches the filter True is returned # otherwise, or if the list is empty, False is returned for message in messages: diff --git a/hydrogram/methods/bots/answer_inline_query.py b/hydrogram/methods/bots/answer_inline_query.py index 829ed6b56..cfd0a9305 100644 --- a/hydrogram/methods/bots/answer_inline_query.py +++ b/hydrogram/methods/bots/answer_inline_query.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import Iterable +from collections.abc import Iterable import hydrogram from hydrogram import raw, types diff --git a/hydrogram/methods/bots/get_bot_commands.py b/hydrogram/methods/bots/get_bot_commands.py index c525a59bb..faa6c556e 100644 --- a/hydrogram/methods/bots/get_bot_commands.py +++ b/hydrogram/methods/bots/get_bot_commands.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List import hydrogram from hydrogram import raw, types @@ -28,7 +27,7 @@ async def get_bot_commands( self: "hydrogram.Client", scope: "types.BotCommandScope" = types.BotCommandScopeDefault(), language_code: str = "", - ) -> List["types.BotCommand"]: + ) -> list["types.BotCommand"]: """Get the current list of the bot's commands for the given scope and user language. Returns Array of BotCommand on success. If commands aren't set, an empty list is returned. diff --git a/hydrogram/methods/bots/get_game_high_scores.py b/hydrogram/methods/bots/get_game_high_scores.py index 9888b3ff4..c117b5736 100644 --- a/hydrogram/methods/bots/get_game_high_scores.py +++ b/hydrogram/methods/bots/get_game_high_scores.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import raw, types @@ -29,7 +29,7 @@ async def get_game_high_scores( user_id: Union[int, str], chat_id: Union[int, str], message_id: Optional[int] = None, - ) -> List["types.GameHighScore"]: + ) -> list["types.GameHighScore"]: """Get data for high score tables. .. include:: /_includes/usable-by/bots.rst diff --git a/hydrogram/methods/bots/set_bot_commands.py b/hydrogram/methods/bots/set_bot_commands.py index 1af646f43..267afbddf 100644 --- a/hydrogram/methods/bots/set_bot_commands.py +++ b/hydrogram/methods/bots/set_bot_commands.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List import hydrogram from hydrogram import raw, types @@ -26,7 +25,7 @@ class SetBotCommands: async def set_bot_commands( self: "hydrogram.Client", - commands: List["types.BotCommand"], + commands: list["types.BotCommand"], scope: "types.BotCommandScope" = types.BotCommandScopeDefault(), language_code: str = "", ) -> bool: diff --git a/hydrogram/methods/chats/add_chat_members.py b/hydrogram/methods/chats/add_chat_members.py index d4b2af960..89edc3cc9 100644 --- a/hydrogram/methods/chats/add_chat_members.py +++ b/hydrogram/methods/chats/add_chat_members.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Union +from typing import Union import hydrogram from hydrogram import raw @@ -27,7 +27,7 @@ class AddChatMembers: async def add_chat_members( self: "hydrogram.Client", chat_id: Union[int, str], - user_ids: Union[Union[int, str], List[Union[int, str]]], + user_ids: Union[Union[int, str], list[Union[int, str]]], forward_limit: int = 100, ) -> bool: """Add new chat members to a group, supergroup or channel diff --git a/hydrogram/methods/chats/archive_chats.py b/hydrogram/methods/chats/archive_chats.py index 3c38cc7c5..f3ac832e3 100644 --- a/hydrogram/methods/chats/archive_chats.py +++ b/hydrogram/methods/chats/archive_chats.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Union +from typing import Union import hydrogram from hydrogram import raw @@ -26,7 +26,7 @@ class ArchiveChats: async def archive_chats( self: "hydrogram.Client", - chat_ids: Union[int, str, List[Union[int, str]]], + chat_ids: Union[int, str, list[Union[int, str]]], ) -> bool: """Archive one or more chats. diff --git a/hydrogram/methods/chats/create_group.py b/hydrogram/methods/chats/create_group.py index 37dd8a2a2..079d3b972 100644 --- a/hydrogram/methods/chats/create_group.py +++ b/hydrogram/methods/chats/create_group.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Union +from typing import Union import hydrogram from hydrogram import raw, types @@ -27,7 +27,7 @@ class CreateGroup: async def create_group( self: "hydrogram.Client", title: str, - users: Union[Union[int, str], List[Union[int, str]]], + users: Union[Union[int, str], list[Union[int, str]]], ) -> "types.Chat": """Create a new basic group. diff --git a/hydrogram/methods/chats/get_chat_event_log.py b/hydrogram/methods/chats/get_chat_event_log.py index 3480fba6f..d427c5e9a 100644 --- a/hydrogram/methods/chats/get_chat_event_log.py +++ b/hydrogram/methods/chats/get_chat_event_log.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import AsyncGenerator, List, Optional, Union +from collections.abc import AsyncGenerator +from typing import Optional, Union import hydrogram from hydrogram import raw, types @@ -31,7 +32,7 @@ async def get_chat_event_log( offset_id: int = 0, limit: int = 0, filters: "types.ChatEventFilter" = None, - user_ids: Optional[List[Union[int, str]]] = None, + user_ids: Optional[list[Union[int, str]]] = None, ) -> Optional[AsyncGenerator["types.ChatEvent", None]]: """Get the actions taken by chat members and administrators in the last 48h. diff --git a/hydrogram/methods/chats/get_chat_members.py b/hydrogram/methods/chats/get_chat_members.py index e0e5b469a..b49f5c169 100644 --- a/hydrogram/methods/chats/get_chat_members.py +++ b/hydrogram/methods/chats/get_chat_members.py @@ -18,7 +18,8 @@ # along with Hydrogram. If not, see . import logging -from typing import AsyncGenerator, Optional, Union +from collections.abc import AsyncGenerator +from typing import Optional, Union import hydrogram from hydrogram import enums, raw, types diff --git a/hydrogram/methods/chats/get_dialogs.py b/hydrogram/methods/chats/get_dialogs.py index 6ccd1aee6..ddc49747e 100644 --- a/hydrogram/methods/chats/get_dialogs.py +++ b/hydrogram/methods/chats/get_dialogs.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import AsyncGenerator, Optional +from collections.abc import AsyncGenerator +from typing import Optional import hydrogram from hydrogram import raw, types, utils diff --git a/hydrogram/methods/chats/get_forum_topics.py b/hydrogram/methods/chats/get_forum_topics.py index 293f254d8..ab1776d9e 100644 --- a/hydrogram/methods/chats/get_forum_topics.py +++ b/hydrogram/methods/chats/get_forum_topics.py @@ -17,7 +17,8 @@ # along with Hydrogram. If not, see . import logging -from typing import AsyncGenerator, Optional, Union +from collections.abc import AsyncGenerator +from typing import Optional, Union import hydrogram from hydrogram import raw, types diff --git a/hydrogram/methods/chats/get_forum_topics_by_id.py b/hydrogram/methods/chats/get_forum_topics_by_id.py index 221315b5d..0fcf44773 100644 --- a/hydrogram/methods/chats/get_forum_topics_by_id.py +++ b/hydrogram/methods/chats/get_forum_topics_by_id.py @@ -17,7 +17,8 @@ # along with Hydrogram. If not, see . import logging -from typing import Iterable, List, Union +from collections.abc import Iterable +from typing import Union import hydrogram from hydrogram import raw, types @@ -28,7 +29,7 @@ class GetForumTopicsByID: async def get_forum_topics_by_id( self: "hydrogram.Client", chat_id: Union[int, str], topic_ids: Union[int, Iterable[int]] - ) -> Union["types.ForumTopic", List["types.ForumTopic"]]: + ) -> Union["types.ForumTopic", list["types.ForumTopic"]]: """Get one or more topic from a chat by using topic identifiers. .. include:: /_includes/usable-by/users.rst diff --git a/hydrogram/methods/chats/get_nearby_chats.py b/hydrogram/methods/chats/get_nearby_chats.py index a2ab8fd5a..dd88a936f 100644 --- a/hydrogram/methods/chats/get_nearby_chats.py +++ b/hydrogram/methods/chats/get_nearby_chats.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List import hydrogram from hydrogram import raw, types, utils @@ -26,7 +25,7 @@ class GetNearbyChats: async def get_nearby_chats( self: "hydrogram.Client", latitude: float, longitude: float - ) -> List["types.Chat"]: + ) -> list["types.Chat"]: """Get nearby chats. .. include:: /_includes/usable-by/users.rst diff --git a/hydrogram/methods/chats/get_send_as_chats.py b/hydrogram/methods/chats/get_send_as_chats.py index 987d9a052..95e38f2ec 100644 --- a/hydrogram/methods/chats/get_send_as_chats.py +++ b/hydrogram/methods/chats/get_send_as_chats.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Union +from typing import Union import hydrogram from hydrogram import raw, types @@ -26,7 +26,7 @@ class GetSendAsChats: async def get_send_as_chats( self: "hydrogram.Client", chat_id: Union[int, str] - ) -> List["types.Chat"]: + ) -> list["types.Chat"]: """Get the list of "send_as" chats available. .. include:: /_includes/usable-by/users.rst diff --git a/hydrogram/methods/chats/unarchive_chats.py b/hydrogram/methods/chats/unarchive_chats.py index 7dfa5c28d..a42091ca1 100644 --- a/hydrogram/methods/chats/unarchive_chats.py +++ b/hydrogram/methods/chats/unarchive_chats.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Union +from typing import Union import hydrogram from hydrogram import raw @@ -26,7 +26,7 @@ class UnarchiveChats: async def unarchive_chats( self: "hydrogram.Client", - chat_ids: Union[int, str, List[Union[int, str]]], + chat_ids: Union[int, str, list[Union[int, str]]], ) -> bool: """Unarchive one or more chats. diff --git a/hydrogram/methods/contacts/delete_contacts.py b/hydrogram/methods/contacts/delete_contacts.py index 1f44808fd..e28bfa552 100644 --- a/hydrogram/methods/contacts/delete_contacts.py +++ b/hydrogram/methods/contacts/delete_contacts.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Union +from typing import Union import hydrogram from hydrogram import raw, types @@ -25,8 +25,8 @@ class DeleteContacts: async def delete_contacts( - self: "hydrogram.Client", user_ids: Union[int, str, List[Union[int, str]]] - ) -> Union["types.User", List["types.User"], None]: + self: "hydrogram.Client", user_ids: Union[int, str, list[Union[int, str]]] + ) -> Union["types.User", list["types.User"], None]: """Delete contacts from your Telegram address book. .. include:: /_includes/usable-by/users.rst diff --git a/hydrogram/methods/contacts/get_contacts.py b/hydrogram/methods/contacts/get_contacts.py index c1d1629a2..3df09cee2 100644 --- a/hydrogram/methods/contacts/get_contacts.py +++ b/hydrogram/methods/contacts/get_contacts.py @@ -18,7 +18,6 @@ # along with Hydrogram. If not, see . import logging -from typing import List import hydrogram from hydrogram import raw, types @@ -27,7 +26,7 @@ class GetContacts: - async def get_contacts(self: "hydrogram.Client") -> List["types.User"]: + async def get_contacts(self: "hydrogram.Client") -> list["types.User"]: """Get contacts from your Telegram address book. .. include:: /_includes/usable-by/users.rst diff --git a/hydrogram/methods/contacts/import_contacts.py b/hydrogram/methods/contacts/import_contacts.py index 140c4dc61..398f4430f 100644 --- a/hydrogram/methods/contacts/import_contacts.py +++ b/hydrogram/methods/contacts/import_contacts.py @@ -17,14 +17,13 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List import hydrogram from hydrogram import raw, types class ImportContacts: - async def import_contacts(self: "hydrogram.Client", contacts: List["types.InputPhoneContact"]): + async def import_contacts(self: "hydrogram.Client", contacts: list["types.InputPhoneContact"]): """Import contacts to your Telegram address book. .. include:: /_includes/usable-by/users.rst diff --git a/hydrogram/methods/invite_links/get_chat_admin_invite_links.py b/hydrogram/methods/invite_links/get_chat_admin_invite_links.py index 38bc9706b..d430e7350 100644 --- a/hydrogram/methods/invite_links/get_chat_admin_invite_links.py +++ b/hydrogram/methods/invite_links/get_chat_admin_invite_links.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import AsyncGenerator, Optional, Union +from collections.abc import AsyncGenerator +from typing import Optional, Union import hydrogram from hydrogram import raw, types diff --git a/hydrogram/methods/invite_links/get_chat_invite_link_joiners.py b/hydrogram/methods/invite_links/get_chat_invite_link_joiners.py index 332c72b4e..95c316165 100644 --- a/hydrogram/methods/invite_links/get_chat_invite_link_joiners.py +++ b/hydrogram/methods/invite_links/get_chat_invite_link_joiners.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import AsyncGenerator, Optional, Union +from collections.abc import AsyncGenerator +from typing import Optional, Union import hydrogram from hydrogram import raw, types diff --git a/hydrogram/methods/invite_links/get_chat_join_requests.py b/hydrogram/methods/invite_links/get_chat_join_requests.py index e3a51b10d..8ff9d940c 100644 --- a/hydrogram/methods/invite_links/get_chat_join_requests.py +++ b/hydrogram/methods/invite_links/get_chat_join_requests.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import AsyncGenerator, Optional, Union +from collections.abc import AsyncGenerator +from typing import Optional, Union import hydrogram from hydrogram import raw, types diff --git a/hydrogram/methods/messages/copy_media_group.py b/hydrogram/methods/messages/copy_media_group.py index 636569ed5..13319a2e5 100644 --- a/hydrogram/methods/messages/copy_media_group.py +++ b/hydrogram/methods/messages/copy_media_group.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import raw, types, utils @@ -30,13 +30,13 @@ async def copy_media_group( chat_id: Union[int, str], from_chat_id: Union[int, str], message_id: int, - captions: Optional[Union[List[str], str]] = None, + captions: Optional[Union[list[str], str]] = None, *, message_thread_id: Optional[int] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, schedule_date: Optional[datetime] = None, - ) -> List["types.Message"]: + ) -> list["types.Message"]: """Copy a media group by providing one of the message ids. .. include:: /_includes/usable-by/users-bots.rst diff --git a/hydrogram/methods/messages/copy_message.py b/hydrogram/methods/messages/copy_message.py index 26f6e9ce0..c6c18a521 100644 --- a/hydrogram/methods/messages/copy_message.py +++ b/hydrogram/methods/messages/copy_message.py @@ -19,7 +19,7 @@ import logging from datetime import datetime -from typing import List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import enums, types @@ -37,7 +37,7 @@ async def copy_message( *, message_thread_id: Optional[int] = None, parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, schedule_date: Optional[datetime] = None, diff --git a/hydrogram/methods/messages/delete_messages.py b/hydrogram/methods/messages/delete_messages.py index 67393ecdd..fac07f82d 100644 --- a/hydrogram/methods/messages/delete_messages.py +++ b/hydrogram/methods/messages/delete_messages.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import Iterable, Union +from collections.abc import Iterable +from typing import Union import hydrogram from hydrogram import raw diff --git a/hydrogram/methods/messages/edit_message_caption.py b/hydrogram/methods/messages/edit_message_caption.py index 2cbcb79c7..0acd955f4 100644 --- a/hydrogram/methods/messages/edit_message_caption.py +++ b/hydrogram/methods/messages/edit_message_caption.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import enums, types @@ -30,7 +30,7 @@ async def edit_message_caption( message_id: int, caption: str, parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, ) -> "types.Message": """Edit the caption of media messages. diff --git a/hydrogram/methods/messages/edit_message_text.py b/hydrogram/methods/messages/edit_message_text.py index 8457e8884..42d765692 100644 --- a/hydrogram/methods/messages/edit_message_text.py +++ b/hydrogram/methods/messages/edit_message_text.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import enums, raw, types, utils @@ -30,7 +30,7 @@ async def edit_message_text( message_id: int, text: str, parse_mode: Optional["enums.ParseMode"] = None, - entities: Optional[List["types.MessageEntity"]] = None, + entities: Optional[list["types.MessageEntity"]] = None, disable_web_page_preview: Optional[bool] = None, reply_markup: "types.InlineKeyboardMarkup" = None, ) -> "types.Message": diff --git a/hydrogram/methods/messages/forward_messages.py b/hydrogram/methods/messages/forward_messages.py index 7ee072473..102696f11 100644 --- a/hydrogram/methods/messages/forward_messages.py +++ b/hydrogram/methods/messages/forward_messages.py @@ -17,8 +17,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . +from collections.abc import Iterable from datetime import datetime -from typing import Iterable, List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import raw, types, utils @@ -35,7 +36,7 @@ async def forward_messages( disable_notification: Optional[bool] = None, schedule_date: Optional[datetime] = None, protect_content: Optional[bool] = None, - ) -> Union["types.Message", List["types.Message"]]: + ) -> Union["types.Message", list["types.Message"]]: """Forward messages of any kind. .. include:: /_includes/usable-by/users-bots.rst diff --git a/hydrogram/methods/messages/get_chat_history.py b/hydrogram/methods/messages/get_chat_history.py index c9fc41c8e..21c39172a 100644 --- a/hydrogram/methods/messages/get_chat_history.py +++ b/hydrogram/methods/messages/get_chat_history.py @@ -17,8 +17,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . +from collections.abc import AsyncGenerator from datetime import datetime -from typing import AsyncGenerator, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import raw, types, utils diff --git a/hydrogram/methods/messages/get_custom_emoji_stickers.py b/hydrogram/methods/messages/get_custom_emoji_stickers.py index b203287f3..dae58a585 100644 --- a/hydrogram/methods/messages/get_custom_emoji_stickers.py +++ b/hydrogram/methods/messages/get_custom_emoji_stickers.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List import hydrogram from hydrogram import raw, types @@ -26,8 +25,8 @@ class GetCustomEmojiStickers: async def get_custom_emoji_stickers( self: "hydrogram.Client", - custom_emoji_ids: List[int], - ) -> List["types.Sticker"]: + custom_emoji_ids: list[int], + ) -> list["types.Sticker"]: """Get information about custom emoji stickers by their identifiers. .. include:: /_includes/usable-by/users-bots.rst diff --git a/hydrogram/methods/messages/get_discussion_replies.py b/hydrogram/methods/messages/get_discussion_replies.py index 22feb7b1d..6d7ee48a2 100644 --- a/hydrogram/methods/messages/get_discussion_replies.py +++ b/hydrogram/methods/messages/get_discussion_replies.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import AsyncGenerator, Optional, Union +from collections.abc import AsyncGenerator +from typing import Optional, Union import hydrogram from hydrogram import raw, types diff --git a/hydrogram/methods/messages/get_media_group.py b/hydrogram/methods/messages/get_media_group.py index 566577035..fe5344f4b 100644 --- a/hydrogram/methods/messages/get_media_group.py +++ b/hydrogram/methods/messages/get_media_group.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . import logging -from typing import List, Union +from typing import Union import hydrogram from hydrogram import types @@ -29,7 +29,7 @@ class GetMediaGroup: async def get_media_group( self: "hydrogram.Client", chat_id: Union[int, str], message_id: int - ) -> List["types.Message"]: + ) -> list["types.Message"]: """Get the media group a message belongs to. .. include:: /_includes/usable-by/users-bots.rst diff --git a/hydrogram/methods/messages/get_messages.py b/hydrogram/methods/messages/get_messages.py index 2d14ade00..520295952 100644 --- a/hydrogram/methods/messages/get_messages.py +++ b/hydrogram/methods/messages/get_messages.py @@ -18,7 +18,8 @@ # along with Hydrogram. If not, see . import logging -from typing import Iterable, List, Optional, Union +from collections.abc import Iterable +from typing import Optional, Union import hydrogram from hydrogram import raw, types, utils @@ -36,7 +37,7 @@ async def get_messages( message_ids: Optional[Union[int, Iterable[int]]] = None, reply_to_message_ids: Optional[Union[int, Iterable[int]]] = None, replies: int = 1, - ) -> Union["types.Message", List["types.Message"]]: + ) -> Union["types.Message", list["types.Message"]]: """Get one or more messages from a chat by using message identifiers. You can retrieve up to 200 messages at once. diff --git a/hydrogram/methods/messages/search_global.py b/hydrogram/methods/messages/search_global.py index b10fb5b52..3bd207de4 100644 --- a/hydrogram/methods/messages/search_global.py +++ b/hydrogram/methods/messages/search_global.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import AsyncGenerator, Optional +from collections.abc import AsyncGenerator +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils diff --git a/hydrogram/methods/messages/search_messages.py b/hydrogram/methods/messages/search_messages.py index 6a51e1c44..8dc2fa145 100644 --- a/hydrogram/methods/messages/search_messages.py +++ b/hydrogram/methods/messages/search_messages.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import AsyncGenerator, List, Optional, Union +from collections.abc import AsyncGenerator +from typing import Optional, Union import hydrogram from hydrogram import enums, raw, types, utils @@ -31,7 +32,7 @@ async def get_chunk( offset: int = 0, limit: int = 100, from_user: Optional[Union[int, str]] = None, -) -> List["types.Message"]: +) -> list["types.Message"]: r = await client.invoke( raw.functions.messages.Search( peer=await client.resolve_peer(chat_id), diff --git a/hydrogram/methods/messages/send_animation.py b/hydrogram/methods/messages/send_animation.py index c41f55303..8d7cb06c3 100644 --- a/hydrogram/methods/messages/send_animation.py +++ b/hydrogram/methods/messages/send_animation.py @@ -20,7 +20,7 @@ import re from datetime import datetime from pathlib import Path -from typing import BinaryIO, Callable, List, Optional, Union +from typing import BinaryIO, Callable, Optional, Union import hydrogram from hydrogram import StopTransmission, enums, raw, types, utils @@ -38,7 +38,7 @@ async def send_animation( message_thread_id: Optional[int] = None, unsave: bool = False, parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, has_spoiler: Optional[bool] = None, duration: int = 0, width: int = 0, diff --git a/hydrogram/methods/messages/send_audio.py b/hydrogram/methods/messages/send_audio.py index 0f5c9667f..0928665a6 100644 --- a/hydrogram/methods/messages/send_audio.py +++ b/hydrogram/methods/messages/send_audio.py @@ -20,7 +20,7 @@ import re from datetime import datetime from pathlib import Path -from typing import BinaryIO, Callable, List, Optional, Union +from typing import BinaryIO, Callable, Optional, Union import hydrogram from hydrogram import StopTransmission, enums, raw, types, utils @@ -37,7 +37,7 @@ async def send_audio( *, message_thread_id: Optional[int] = None, parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, duration: int = 0, performer: Optional[str] = None, title: Optional[str] = None, diff --git a/hydrogram/methods/messages/send_cached_media.py b/hydrogram/methods/messages/send_cached_media.py index b1c3e75bb..a39c9cba7 100644 --- a/hydrogram/methods/messages/send_cached_media.py +++ b/hydrogram/methods/messages/send_cached_media.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import enums, raw, types, utils @@ -33,7 +33,7 @@ async def send_cached_media( *, message_thread_id: Optional[int] = None, parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, schedule_date: Optional[datetime] = None, diff --git a/hydrogram/methods/messages/send_document.py b/hydrogram/methods/messages/send_document.py index 63c688b9f..382cbbcba 100644 --- a/hydrogram/methods/messages/send_document.py +++ b/hydrogram/methods/messages/send_document.py @@ -20,7 +20,7 @@ import re from datetime import datetime from pathlib import Path -from typing import BinaryIO, Callable, List, Optional, Union +from typing import BinaryIO, Callable, Optional, Union import hydrogram from hydrogram import StopTransmission, enums, raw, types, utils @@ -38,7 +38,7 @@ async def send_document( *, message_thread_id: Optional[int] = None, parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, file_name: Optional[str] = None, force_document: Optional[bool] = None, disable_notification: Optional[bool] = None, diff --git a/hydrogram/methods/messages/send_media_group.py b/hydrogram/methods/messages/send_media_group.py index 727581b21..368e6f5d1 100644 --- a/hydrogram/methods/messages/send_media_group.py +++ b/hydrogram/methods/messages/send_media_group.py @@ -21,7 +21,7 @@ import re from datetime import datetime from pathlib import Path -from typing import List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import raw, types, utils @@ -35,7 +35,7 @@ class SendMediaGroup: async def send_media_group( self: "hydrogram.Client", chat_id: Union[int, str], - media: List[ + media: list[ Union[ "types.InputMediaPhoto", "types.InputMediaVideo", @@ -49,7 +49,7 @@ async def send_media_group( reply_to_message_id: Optional[int] = None, schedule_date: Optional[datetime] = None, protect_content: Optional[bool] = None, - ) -> List["types.Message"]: + ) -> list["types.Message"]: """Send a group of photos or videos as an album. .. include:: /_includes/usable-by/users-bots.rst diff --git a/hydrogram/methods/messages/send_message.py b/hydrogram/methods/messages/send_message.py index de65196ca..3dc66a9f9 100644 --- a/hydrogram/methods/messages/send_message.py +++ b/hydrogram/methods/messages/send_message.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import enums, raw, types, utils @@ -32,7 +32,7 @@ async def send_message( *, message_thread_id: Optional[int] = None, parse_mode: Optional["enums.ParseMode"] = None, - entities: Optional[List["types.MessageEntity"]] = None, + entities: Optional[list["types.MessageEntity"]] = None, disable_web_page_preview: Optional[bool] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, diff --git a/hydrogram/methods/messages/send_photo.py b/hydrogram/methods/messages/send_photo.py index 7e99eb53c..99bf0ff83 100644 --- a/hydrogram/methods/messages/send_photo.py +++ b/hydrogram/methods/messages/send_photo.py @@ -20,7 +20,7 @@ import re from datetime import datetime from pathlib import Path -from typing import BinaryIO, Callable, List, Optional, Union +from typing import BinaryIO, Callable, Optional, Union import hydrogram from hydrogram import enums, raw, types, utils @@ -37,7 +37,7 @@ async def send_photo( *, message_thread_id: Optional[int] = None, parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, has_spoiler: Optional[bool] = None, ttl_seconds: Optional[int] = None, disable_notification: Optional[bool] = None, diff --git a/hydrogram/methods/messages/send_poll.py b/hydrogram/methods/messages/send_poll.py index 2c4a0ac4d..d3ea16ea9 100644 --- a/hydrogram/methods/messages/send_poll.py +++ b/hydrogram/methods/messages/send_poll.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import enums, raw, types, utils @@ -29,7 +29,7 @@ async def send_poll( self: "hydrogram.Client", chat_id: Union[int, str], question: str, - options: List[str], + options: list[str], *, message_thread_id: Optional[int] = None, is_anonymous: bool = True, @@ -38,7 +38,7 @@ async def send_poll( correct_option_id: Optional[int] = None, explanation: Optional[str] = None, explanation_parse_mode: "enums.ParseMode" = None, - explanation_entities: Optional[List["types.MessageEntity"]] = None, + explanation_entities: Optional[list["types.MessageEntity"]] = None, open_period: Optional[int] = None, close_date: Optional[datetime] = None, is_closed: Optional[bool] = None, diff --git a/hydrogram/methods/messages/send_video.py b/hydrogram/methods/messages/send_video.py index 7e27e79fa..52e11d00d 100644 --- a/hydrogram/methods/messages/send_video.py +++ b/hydrogram/methods/messages/send_video.py @@ -20,7 +20,7 @@ import re from datetime import datetime from pathlib import Path -from typing import BinaryIO, Callable, List, Optional, Union +from typing import BinaryIO, Callable, Optional, Union import hydrogram from hydrogram import StopTransmission, enums, raw, types, utils @@ -37,7 +37,7 @@ async def send_video( *, message_thread_id: Optional[int] = None, parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, has_spoiler: Optional[bool] = None, ttl_seconds: Optional[int] = None, duration: int = 0, diff --git a/hydrogram/methods/messages/send_voice.py b/hydrogram/methods/messages/send_voice.py index 4f96de150..fcd2a5bfa 100644 --- a/hydrogram/methods/messages/send_voice.py +++ b/hydrogram/methods/messages/send_voice.py @@ -20,7 +20,7 @@ import re from datetime import datetime from pathlib import Path -from typing import BinaryIO, Callable, List, Optional, Union +from typing import BinaryIO, Callable, Optional, Union import hydrogram from hydrogram import StopTransmission, enums, raw, types, utils @@ -37,7 +37,7 @@ async def send_voice( *, message_thread_id: Optional[int] = None, parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, duration: int = 0, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, diff --git a/hydrogram/methods/messages/vote_poll.py b/hydrogram/methods/messages/vote_poll.py index 1acc0dbcf..5f9e88414 100644 --- a/hydrogram/methods/messages/vote_poll.py +++ b/hydrogram/methods/messages/vote_poll.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Union +from typing import Union import hydrogram from hydrogram import raw, types @@ -28,7 +28,7 @@ async def vote_poll( self: "hydrogram.Client", chat_id: Union[int, str], message_id: id, - options: Union[int, List[int]], + options: Union[int, list[int]], ) -> "types.Poll": """Vote a poll. diff --git a/hydrogram/methods/users/delete_profile_photos.py b/hydrogram/methods/users/delete_profile_photos.py index be8e6414f..b323147df 100644 --- a/hydrogram/methods/users/delete_profile_photos.py +++ b/hydrogram/methods/users/delete_profile_photos.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Union +from typing import Union import hydrogram from hydrogram import raw, utils @@ -26,7 +26,7 @@ class DeleteProfilePhotos: async def delete_profile_photos( - self: "hydrogram.Client", photo_ids: Union[str, List[str]] + self: "hydrogram.Client", photo_ids: Union[str, list[str]] ) -> bool: """Delete your own profile photos. diff --git a/hydrogram/methods/users/get_chat_photos.py b/hydrogram/methods/users/get_chat_photos.py index 2adddb26c..5adb5b0e7 100644 --- a/hydrogram/methods/users/get_chat_photos.py +++ b/hydrogram/methods/users/get_chat_photos.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import AsyncGenerator, Optional, Union +from collections.abc import AsyncGenerator +from typing import Optional, Union import hydrogram from hydrogram import raw, types, utils diff --git a/hydrogram/methods/users/get_common_chats.py b/hydrogram/methods/users/get_common_chats.py index a588d4fd1..3d9e4fcc0 100644 --- a/hydrogram/methods/users/get_common_chats.py +++ b/hydrogram/methods/users/get_common_chats.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Union +from typing import Union import hydrogram from hydrogram import raw, types @@ -26,7 +26,7 @@ class GetCommonChats: async def get_common_chats( self: "hydrogram.Client", user_id: Union[int, str] - ) -> List["types.Chat"]: + ) -> list["types.Chat"]: """Get the common chats you have with a user. .. include:: /_includes/usable-by/users.rst diff --git a/hydrogram/methods/users/get_default_emoji_statuses.py b/hydrogram/methods/users/get_default_emoji_statuses.py index 5840ec7ce..bc504263c 100644 --- a/hydrogram/methods/users/get_default_emoji_statuses.py +++ b/hydrogram/methods/users/get_default_emoji_statuses.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List import hydrogram from hydrogram import raw, types @@ -26,7 +25,7 @@ class GetDefaultEmojiStatuses: async def get_default_emoji_statuses( self: "hydrogram.Client", - ) -> List["types.EmojiStatus"]: + ) -> list["types.EmojiStatus"]: """Get the default emoji statuses. .. include:: /_includes/usable-by/users-bots.rst diff --git a/hydrogram/methods/users/get_users.py b/hydrogram/methods/users/get_users.py index 262d374b4..497e9a9f1 100644 --- a/hydrogram/methods/users/get_users.py +++ b/hydrogram/methods/users/get_users.py @@ -18,7 +18,8 @@ # along with Hydrogram. If not, see . import asyncio -from typing import Iterable, List, Union +from collections.abc import Iterable +from typing import Union import hydrogram from hydrogram import raw, types @@ -27,7 +28,7 @@ class GetUsers: async def get_users( self: "hydrogram.Client", user_ids: Union[int, str, Iterable[Union[int, str]]] - ) -> Union["types.User", List["types.User"]]: + ) -> Union["types.User", list["types.User"]]: """Get information about a user. You can retrieve up to 200 users at once. diff --git a/hydrogram/methods/utilities/compose.py b/hydrogram/methods/utilities/compose.py index 5e37411ec..f9532f12a 100644 --- a/hydrogram/methods/utilities/compose.py +++ b/hydrogram/methods/utilities/compose.py @@ -18,14 +18,13 @@ # along with Hydrogram. If not, see . import asyncio -from typing import List import hydrogram from .idle import idle -async def compose(clients: List["hydrogram.Client"], sequential: bool = False): +async def compose(clients: list["hydrogram.Client"], sequential: bool = False): """Run multiple clients at once. This method can be used to run multiple clients at once and can be found directly in the ``hydrogram`` package. diff --git a/hydrogram/raw/core/future_salts.py b/hydrogram/raw/core/future_salts.py index a82b5b1ce..f42718b85 100644 --- a/hydrogram/raw/core/future_salts.py +++ b/hydrogram/raw/core/future_salts.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from io import BytesIO -from typing import Any, List +from typing import Any from .future_salt import FutureSalt from .primitives.int import Int, Long @@ -32,7 +32,7 @@ class FutureSalts(TLObject): QUALNAME = "FutureSalts" - def __init__(self, req_msg_id: int, now: int, salts: List[FutureSalt]): + def __init__(self, req_msg_id: int, now: int, salts: list[FutureSalt]): self.req_msg_id = req_msg_id self.now = now self.salts = salts diff --git a/hydrogram/raw/core/list.py b/hydrogram/raw/core/list.py index fa7da6ce3..ab1acf53e 100644 --- a/hydrogram/raw/core/list.py +++ b/hydrogram/raw/core/list.py @@ -18,11 +18,10 @@ # along with Hydrogram. If not, see . from typing import Any -from typing import List as TList from .tl_object import TLObject -class List(TList[Any], TLObject): +class List(list[Any], TLObject): def __repr__(self) -> str: return f"hydrogram.raw.core.List([{','.join(TLObject.__repr__(i) for i in self)}])" diff --git a/hydrogram/raw/core/msg_container.py b/hydrogram/raw/core/msg_container.py index ab86ce674..690b1bfa1 100644 --- a/hydrogram/raw/core/msg_container.py +++ b/hydrogram/raw/core/msg_container.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from io import BytesIO -from typing import Any, List +from typing import Any from .message import Message from .primitives.int import Int @@ -32,7 +32,7 @@ class MsgContainer(TLObject): QUALNAME = "MsgContainer" - def __init__(self, messages: List[Message]): + def __init__(self, messages: list[Message]): self.messages = messages @staticmethod diff --git a/hydrogram/raw/core/tl_object.py b/hydrogram/raw/core/tl_object.py index dea6c4921..0895a66e2 100644 --- a/hydrogram/raw/core/tl_object.py +++ b/hydrogram/raw/core/tl_object.py @@ -19,13 +19,13 @@ from io import BytesIO from json import dumps -from typing import Any, Dict, List, Union, cast +from typing import Any, Union, cast from hydrogram.raw.all import objects class TLObject: - __slots__: List[str] = [] + __slots__: list[str] = [] QUALNAME = "Base" @@ -37,7 +37,7 @@ def write(self, *args: Any) -> bytes: pass @staticmethod - def default(obj: "TLObject") -> Union[str, Dict[str, str]]: + def default(obj: "TLObject") -> Union[str, dict[str, str]]: if isinstance(obj, bytes): return repr(obj) diff --git a/hydrogram/session/internals/data_center.py b/hydrogram/session/internals/data_center.py index 4cd84eea6..f38c7e910 100644 --- a/hydrogram/session/internals/data_center.py +++ b/hydrogram/session/internals/data_center.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import ClassVar, Tuple +from typing import ClassVar class DataCenter: @@ -58,7 +58,7 @@ class DataCenter: 4: "2001:067c:04e8:f004:0000:0000:0000:000b", } - def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool, media: bool) -> Tuple[str, int]: + def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool, media: bool) -> tuple[str, int]: if test_mode: ip = cls.TEST_IPV6[dc_id] if ipv6 else cls.TEST[dc_id] diff --git a/hydrogram/storage/base.py b/hydrogram/storage/base.py index f8eb09c09..b167e5fdf 100644 --- a/hydrogram/storage/base.py +++ b/hydrogram/storage/base.py @@ -20,7 +20,6 @@ import base64 import struct from abc import ABC, abstractmethod -from typing import List, Tuple class BaseStorage(ABC): @@ -58,7 +57,7 @@ async def delete(self): raise NotImplementedError @abstractmethod - async def update_peers(self, peers: List[Tuple[int, int, str, str, str]]): + async def update_peers(self, peers: list[tuple[int, int, str, str, str]]): """ Update the peers table with the provided information. diff --git a/hydrogram/storage/sqlite_storage.py b/hydrogram/storage/sqlite_storage.py index ba3721f1f..ba22bc0c0 100644 --- a/hydrogram/storage/sqlite_storage.py +++ b/hydrogram/storage/sqlite_storage.py @@ -22,7 +22,7 @@ import struct import time from pathlib import Path -from typing import Any, List, Optional, Tuple +from typing import Any, Optional import aiosqlite @@ -180,7 +180,7 @@ async def delete(self): if self.database != ":memory:": Path(self.database).unlink() - async def update_peers(self, peers: List[Tuple[int, int, str, str, str]]): + async def update_peers(self, peers: list[tuple[int, int, str, str, str]]): await self.conn.executemany( "REPLACE INTO peers (id, access_hash, type, username, phone_number)" "VALUES (?, ?, ?, ?, ?)", diff --git a/hydrogram/types/authorization/terms_of_service.py b/hydrogram/types/authorization/terms_of_service.py index 8a3996f61..2c78786c1 100644 --- a/hydrogram/types/authorization/terms_of_service.py +++ b/hydrogram/types/authorization/terms_of_service.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List from hydrogram import raw, types from hydrogram.types.object import Object @@ -37,7 +36,7 @@ class TermsOfService(Object): Special entities like URLs that appear in the text. """ - def __init__(self, *, id: str, text: str, entities: List["types.MessageEntity"]): + def __init__(self, *, id: str, text: str, entities: list["types.MessageEntity"]): super().__init__() self.id = id diff --git a/hydrogram/types/bots_and_keyboards/callback_query.py b/hydrogram/types/bots_and_keyboards/callback_query.py index a76304b45..7dfa616ba 100644 --- a/hydrogram/types/bots_and_keyboards/callback_query.py +++ b/hydrogram/types/bots_and_keyboards/callback_query.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Match, Optional, Union +from re import Match +from typing import Optional, Union import hydrogram from hydrogram import enums, raw, types, utils @@ -72,7 +73,7 @@ def __init__( inline_message_id: Optional[str] = None, data: Optional[Union[str, bytes]] = None, game_short_name: Optional[str] = None, - matches: Optional[List[Match]] = None, + matches: Optional[list[Match]] = None, ): super().__init__(client) diff --git a/hydrogram/types/bots_and_keyboards/inline_keyboard_markup.py b/hydrogram/types/bots_and_keyboards/inline_keyboard_markup.py index 5fb551b26..ec5a06fe8 100644 --- a/hydrogram/types/bots_and_keyboards/inline_keyboard_markup.py +++ b/hydrogram/types/bots_and_keyboards/inline_keyboard_markup.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List import hydrogram from hydrogram import raw, types @@ -32,7 +31,7 @@ class InlineKeyboardMarkup(Object): List of button rows, each represented by a List of InlineKeyboardButton objects. """ - def __init__(self, inline_keyboard: List[List["types.InlineKeyboardButton"]]): + def __init__(self, inline_keyboard: list[list["types.InlineKeyboardButton"]]): super().__init__() self.inline_keyboard = inline_keyboard diff --git a/hydrogram/types/bots_and_keyboards/reply_keyboard_markup.py b/hydrogram/types/bots_and_keyboards/reply_keyboard_markup.py index fded8b8d0..0e8d092bd 100644 --- a/hydrogram/types/bots_and_keyboards/reply_keyboard_markup.py +++ b/hydrogram/types/bots_and_keyboards/reply_keyboard_markup.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import raw, types @@ -58,7 +58,7 @@ class ReplyKeyboardMarkup(Object): def __init__( self, - keyboard: List[List[Union["types.KeyboardButton", str]]], + keyboard: list[list[Union["types.KeyboardButton", str]]], is_persistent: Optional[bool] = None, resize_keyboard: Optional[bool] = None, one_time_keyboard: Optional[bool] = None, diff --git a/hydrogram/types/inline_mode/inline_query.py b/hydrogram/types/inline_mode/inline_query.py index 7c69b4a00..ecce822b5 100644 --- a/hydrogram/types/inline_mode/inline_query.py +++ b/hydrogram/types/inline_mode/inline_query.py @@ -17,7 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Match, Optional +from re import Match +from typing import Optional import hydrogram from hydrogram import enums, raw, types @@ -64,7 +65,7 @@ def __init__( offset: str, chat_type: "enums.ChatType", location: "types.Location" = None, - matches: Optional[List[Match]] = None, + matches: Optional[list[Match]] = None, ): super().__init__(client) @@ -110,7 +111,7 @@ def _parse(client, inline_query: raw.types.UpdateBotInlineQuery, users: dict) -> async def answer( self, - results: List["types.InlineQueryResult"], + results: list["types.InlineQueryResult"], cache_time: int = 300, is_gallery: bool = False, is_personal: bool = False, diff --git a/hydrogram/types/inline_mode/inline_query_result_animation.py b/hydrogram/types/inline_mode/inline_query_result_animation.py index c99d7d557..7d4c95895 100644 --- a/hydrogram/types/inline_mode/inline_query_result_animation.py +++ b/hydrogram/types/inline_mode/inline_query_result_animation.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -91,7 +91,7 @@ def __init__( description: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, ): diff --git a/hydrogram/types/inline_mode/inline_query_result_audio.py b/hydrogram/types/inline_mode/inline_query_result_audio.py index fa23ed0e9..267509239 100644 --- a/hydrogram/types/inline_mode/inline_query_result_audio.py +++ b/hydrogram/types/inline_mode/inline_query_result_audio.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -75,7 +75,7 @@ def __init__( audio_duration: int = 0, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, ): diff --git a/hydrogram/types/inline_mode/inline_query_result_cached_animation.py b/hydrogram/types/inline_mode/inline_query_result_cached_animation.py index aff1fc575..c6a1b803b 100644 --- a/hydrogram/types/inline_mode/inline_query_result_cached_animation.py +++ b/hydrogram/types/inline_mode/inline_query_result_cached_animation.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -68,7 +68,7 @@ def __init__( title: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, ): diff --git a/hydrogram/types/inline_mode/inline_query_result_cached_audio.py b/hydrogram/types/inline_mode/inline_query_result_cached_audio.py index 75cf0b06d..6c2a93704 100644 --- a/hydrogram/types/inline_mode/inline_query_result_cached_audio.py +++ b/hydrogram/types/inline_mode/inline_query_result_cached_audio.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -63,7 +63,7 @@ def __init__( id: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, ): diff --git a/hydrogram/types/inline_mode/inline_query_result_cached_document.py b/hydrogram/types/inline_mode/inline_query_result_cached_document.py index f5201cff4..f78871277 100644 --- a/hydrogram/types/inline_mode/inline_query_result_cached_document.py +++ b/hydrogram/types/inline_mode/inline_query_result_cached_document.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -71,7 +71,7 @@ def __init__( description: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, ): diff --git a/hydrogram/types/inline_mode/inline_query_result_cached_photo.py b/hydrogram/types/inline_mode/inline_query_result_cached_photo.py index 994941b83..0ae1b12f0 100644 --- a/hydrogram/types/inline_mode/inline_query_result_cached_photo.py +++ b/hydrogram/types/inline_mode/inline_query_result_cached_photo.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -71,7 +71,7 @@ def __init__( description: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, ): diff --git a/hydrogram/types/inline_mode/inline_query_result_cached_video.py b/hydrogram/types/inline_mode/inline_query_result_cached_video.py index e8cb8a27f..d59a3ead2 100644 --- a/hydrogram/types/inline_mode/inline_query_result_cached_video.py +++ b/hydrogram/types/inline_mode/inline_query_result_cached_video.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -72,7 +72,7 @@ def __init__( description: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, ): diff --git a/hydrogram/types/inline_mode/inline_query_result_cached_voice.py b/hydrogram/types/inline_mode/inline_query_result_cached_voice.py index 5a845a0e3..d66d26311 100644 --- a/hydrogram/types/inline_mode/inline_query_result_cached_voice.py +++ b/hydrogram/types/inline_mode/inline_query_result_cached_voice.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -68,7 +68,7 @@ def __init__( title: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, ): diff --git a/hydrogram/types/inline_mode/inline_query_result_document.py b/hydrogram/types/inline_mode/inline_query_result_document.py index 0a1298884..8efc274ea 100644 --- a/hydrogram/types/inline_mode/inline_query_result_document.py +++ b/hydrogram/types/inline_mode/inline_query_result_document.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -83,7 +83,7 @@ def __init__( id: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, description: str = "", reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, diff --git a/hydrogram/types/inline_mode/inline_query_result_photo.py b/hydrogram/types/inline_mode/inline_query_result_photo.py index ffc53acc1..cdca21b79 100644 --- a/hydrogram/types/inline_mode/inline_query_result_photo.py +++ b/hydrogram/types/inline_mode/inline_query_result_photo.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -85,7 +85,7 @@ def __init__( description: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, ): diff --git a/hydrogram/types/inline_mode/inline_query_result_video.py b/hydrogram/types/inline_mode/inline_query_result_video.py index 3acabe510..651c654cb 100644 --- a/hydrogram/types/inline_mode/inline_query_result_video.py +++ b/hydrogram/types/inline_mode/inline_query_result_video.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -93,7 +93,7 @@ def __init__( description: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, ): diff --git a/hydrogram/types/inline_mode/inline_query_result_voice.py b/hydrogram/types/inline_mode/inline_query_result_voice.py index 0bc8108ff..994ec8f46 100644 --- a/hydrogram/types/inline_mode/inline_query_result_voice.py +++ b/hydrogram/types/inline_mode/inline_query_result_voice.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -71,7 +71,7 @@ def __init__( voice_duration: int = 0, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, ): diff --git a/hydrogram/types/input_media/input_media.py b/hydrogram/types/input_media/input_media.py index 75ae50590..4b79ef2a5 100644 --- a/hydrogram/types/input_media/input_media.py +++ b/hydrogram/types/input_media/input_media.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import BinaryIO, List, Optional, Union +from typing import BinaryIO, Optional, Union from hydrogram.types.messages_and_media import MessageEntity from hydrogram.types.object import Object @@ -40,7 +40,7 @@ def __init__( media: Union[str, BinaryIO], caption: str = "", parse_mode: Optional[str] = None, - caption_entities: Optional[List[MessageEntity]] = None, + caption_entities: Optional[list[MessageEntity]] = None, ): super().__init__() diff --git a/hydrogram/types/input_media/input_media_animation.py b/hydrogram/types/input_media/input_media_animation.py index 8d31f7cfa..262f0744e 100644 --- a/hydrogram/types/input_media/input_media_animation.py +++ b/hydrogram/types/input_media/input_media_animation.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import BinaryIO, List, Optional, Union +from typing import BinaryIO, Optional, Union from hydrogram import enums from hydrogram.types.messages_and_media import MessageEntity @@ -72,7 +72,7 @@ def __init__( thumb: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List[MessageEntity]] = None, + caption_entities: Optional[list[MessageEntity]] = None, width: int = 0, height: int = 0, duration: int = 0, diff --git a/hydrogram/types/input_media/input_media_audio.py b/hydrogram/types/input_media/input_media_audio.py index 6cd7c2761..1de318867 100644 --- a/hydrogram/types/input_media/input_media_audio.py +++ b/hydrogram/types/input_media/input_media_audio.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import BinaryIO, List, Optional, Union +from typing import BinaryIO, Optional, Union from hydrogram import enums from hydrogram.types.messages_and_media import MessageEntity @@ -71,7 +71,7 @@ def __init__( thumb: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List[MessageEntity]] = None, + caption_entities: Optional[list[MessageEntity]] = None, duration: int = 0, performer: str = "", title: str = "", diff --git a/hydrogram/types/input_media/input_media_document.py b/hydrogram/types/input_media/input_media_document.py index 789b402ca..59aa804c5 100644 --- a/hydrogram/types/input_media/input_media_document.py +++ b/hydrogram/types/input_media/input_media_document.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import BinaryIO, List, Optional, Union +from typing import BinaryIO, Optional, Union from hydrogram import enums from hydrogram.types.messages_and_media import MessageEntity @@ -60,7 +60,7 @@ def __init__( thumb: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List[MessageEntity]] = None, + caption_entities: Optional[list[MessageEntity]] = None, ): super().__init__(media, caption, parse_mode, caption_entities) diff --git a/hydrogram/types/input_media/input_media_photo.py b/hydrogram/types/input_media/input_media_photo.py index 5d6d7a14c..1583a8bf2 100644 --- a/hydrogram/types/input_media/input_media_photo.py +++ b/hydrogram/types/input_media/input_media_photo.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import BinaryIO, List, Optional, Union +from typing import BinaryIO, Optional, Union from hydrogram import enums from hydrogram.types.messages_and_media import MessageEntity @@ -57,7 +57,7 @@ def __init__( media: Union[str, BinaryIO], caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List[MessageEntity]] = None, + caption_entities: Optional[list[MessageEntity]] = None, has_spoiler: Optional[bool] = None, ): super().__init__(media, caption, parse_mode, caption_entities) diff --git a/hydrogram/types/input_media/input_media_video.py b/hydrogram/types/input_media/input_media_video.py index ec97d743f..255590a9b 100644 --- a/hydrogram/types/input_media/input_media_video.py +++ b/hydrogram/types/input_media/input_media_video.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import BinaryIO, List, Optional, Union +from typing import BinaryIO, Optional, Union from hydrogram import enums from hydrogram.types.messages_and_media import MessageEntity @@ -76,7 +76,7 @@ def __init__( thumb: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List[MessageEntity]] = None, + caption_entities: Optional[list[MessageEntity]] = None, width: int = 0, height: int = 0, duration: int = 0, diff --git a/hydrogram/types/input_message_content/input_text_message_content.py b/hydrogram/types/input_message_content/input_text_message_content.py index 0bd0463f0..e8b9bd6a7 100644 --- a/hydrogram/types/input_message_content/input_text_message_content.py +++ b/hydrogram/types/input_message_content/input_text_message_content.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -47,7 +47,7 @@ def __init__( self, message_text: str, parse_mode: Optional["enums.ParseMode"] = None, - entities: Optional[List["types.MessageEntity"]] = None, + entities: Optional[list["types.MessageEntity"]] = None, disable_web_page_preview: Optional[bool] = None, ): super().__init__() diff --git a/hydrogram/types/messages_and_media/animation.py b/hydrogram/types/messages_and_media/animation.py index 314c6e7c5..96f6626ed 100644 --- a/hydrogram/types/messages_and_media/animation.py +++ b/hydrogram/types/messages_and_media/animation.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import raw, types, utils @@ -75,7 +75,7 @@ def __init__( mime_type: Optional[str] = None, file_size: Optional[int] = None, date: Optional[datetime] = None, - thumbs: Optional[List["types.Thumbnail"]] = None, + thumbs: Optional[list["types.Thumbnail"]] = None, ): super().__init__(client) diff --git a/hydrogram/types/messages_and_media/audio.py b/hydrogram/types/messages_and_media/audio.py index e7d707884..945c147f5 100644 --- a/hydrogram/types/messages_and_media/audio.py +++ b/hydrogram/types/messages_and_media/audio.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import raw, types, utils @@ -75,7 +75,7 @@ def __init__( mime_type: Optional[str] = None, file_size: Optional[int] = None, date: Optional[datetime] = None, - thumbs: Optional[List["types.Thumbnail"]] = None, + thumbs: Optional[list["types.Thumbnail"]] = None, ): super().__init__(client) diff --git a/hydrogram/types/messages_and_media/document.py b/hydrogram/types/messages_and_media/document.py index 49ba8eb6c..cc53c2687 100644 --- a/hydrogram/types/messages_and_media/document.py +++ b/hydrogram/types/messages_and_media/document.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import raw, types, utils @@ -63,7 +63,7 @@ def __init__( mime_type: Optional[str] = None, file_size: Optional[int] = None, date: Optional[datetime] = None, - thumbs: Optional[List["types.Thumbnail"]] = None, + thumbs: Optional[list["types.Thumbnail"]] = None, ): super().__init__(client) diff --git a/hydrogram/types/messages_and_media/message.py b/hydrogram/types/messages_and_media/message.py index 7240ff0fe..b3076ff7a 100644 --- a/hydrogram/types/messages_and_media/message.py +++ b/hydrogram/types/messages_and_media/message.py @@ -20,7 +20,8 @@ import logging from datetime import datetime from functools import partial -from typing import BinaryIO, Callable, List, Match, Optional, Union +from re import Match +from typing import BinaryIO, Callable, Optional, Union import hydrogram from hydrogram import enums, raw, types, utils @@ -368,8 +369,8 @@ def __init__( has_protected_content: Optional[bool] = None, has_media_spoiler: Optional[bool] = None, text: Str = None, - entities: Optional[List["types.MessageEntity"]] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + entities: Optional[list["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, audio: "types.Audio" = None, document: "types.Document" = None, photo: "types.Photo" = None, @@ -386,7 +387,7 @@ def __init__( web_page: "types.WebPage" = None, poll: "types.Poll" = None, dice: "types.Dice" = None, - new_chat_members: Optional[List["types.User"]] = None, + new_chat_members: Optional[list["types.User"]] = None, left_chat_member: "types.User" = None, new_chat_title: Optional[str] = None, new_chat_photo: "types.Photo" = None, @@ -402,8 +403,8 @@ def __init__( forwards: Optional[int] = None, via_bot: "types.User" = None, outgoing: Optional[bool] = None, - matches: Optional[List[Match]] = None, - command: Optional[List[str]] = None, + matches: Optional[list[Match]] = None, + command: Optional[list[str]] = None, forum_topic_created: "types.ForumTopicCreated" = None, forum_topic_closed: "types.ForumTopicClosed" = None, forum_topic_reopened: "types.ForumTopicReopened" = None, @@ -421,7 +422,7 @@ def __init__( "types.ReplyKeyboardRemove", "types.ForceReply", ] = None, - reactions: Optional[List["types.Reaction"]] = None, + reactions: Optional[list["types.Reaction"]] = None, ): super().__init__(client) @@ -1000,7 +1001,7 @@ def link(self) -> str: return f"https://t.me/{self.chat.username}/{self.id}" return f"https://t.me/c/{utils.get_channel_id(self.chat.id)}/{self.id}" - async def get_media_group(self) -> List["types.Message"]: + async def get_media_group(self) -> list["types.Message"]: """Bound method *get_media_group* of :obj:`~hydrogram.types.Message`. Use as a shortcut for: @@ -1031,7 +1032,7 @@ async def reply_text( text: str, quote: Optional[bool] = None, parse_mode: Optional["enums.ParseMode"] = None, - entities: Optional[List["types.MessageEntity"]] = None, + entities: Optional[list["types.MessageEntity"]] = None, disable_web_page_preview: Optional[bool] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, @@ -1129,7 +1130,7 @@ async def reply_animation( quote: Optional[bool] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, has_spoiler: Optional[bool] = None, duration: int = 0, width: int = 0, @@ -1275,7 +1276,7 @@ async def reply_audio( quote: Optional[bool] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, duration: int = 0, performer: Optional[str] = None, title: Optional[str] = None, @@ -1416,7 +1417,7 @@ async def reply_cached_media( quote: Optional[bool] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, reply_markup: Union[ @@ -1629,7 +1630,7 @@ async def reply_document( thumb: Optional[str] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, file_name: Optional[str] = None, force_document: Optional[bool] = None, disable_notification: Optional[bool] = None, @@ -1982,11 +1983,11 @@ async def reply_location( async def reply_media_group( self, - media: List[Union["types.InputMediaPhoto", "types.InputMediaVideo"]], + media: list[Union["types.InputMediaPhoto", "types.InputMediaVideo"]], quote: Optional[bool] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, - ) -> List["types.Message"]: + ) -> list["types.Message"]: """Bound method *reply_media_group* of :obj:`~hydrogram.types.Message`. Use as a shortcut for: @@ -2049,7 +2050,7 @@ async def reply_photo( quote: Optional[bool] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, has_spoiler: Optional[bool] = None, ttl_seconds: Optional[int] = None, disable_notification: Optional[bool] = None, @@ -2176,14 +2177,14 @@ async def reply_photo( async def reply_poll( self, question: str, - options: List[str], + options: list[str], is_anonymous: bool = True, type: "enums.PollType" = enums.PollType.REGULAR, allows_multiple_answers: Optional[bool] = None, correct_option_id: Optional[int] = None, explanation: Optional[str] = None, explanation_parse_mode: "enums.ParseMode" = None, - explanation_entities: Optional[List["types.MessageEntity"]] = None, + explanation_entities: Optional[list["types.MessageEntity"]] = None, open_period: Optional[int] = None, close_date: Optional[datetime] = None, is_closed: Optional[bool] = None, @@ -2528,7 +2529,7 @@ async def reply_video( quote: Optional[bool] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, has_spoiler: Optional[bool] = None, ttl_seconds: Optional[int] = None, duration: int = 0, @@ -2806,7 +2807,7 @@ async def reply_voice( quote: Optional[bool] = None, caption: str = "", parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, duration: int = 0, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, @@ -2927,7 +2928,7 @@ async def edit_text( self, text: str, parse_mode: Optional["enums.ParseMode"] = None, - entities: Optional[List["types.MessageEntity"]] = None, + entities: Optional[list["types.MessageEntity"]] = None, disable_web_page_preview: Optional[bool] = None, reply_markup: "types.InlineKeyboardMarkup" = None, ) -> "Message": @@ -2989,7 +2990,7 @@ async def edit_caption( self, caption: str, parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, reply_markup: "types.InlineKeyboardMarkup" = None, ) -> "Message": """Bound method *edit_caption* of :obj:`~hydrogram.types.Message`. @@ -3121,7 +3122,7 @@ async def forward( message_thread_id: Optional[int] = None, disable_notification: Optional[bool] = None, schedule_date: Optional[datetime] = None, - ) -> Union["types.Message", List["types.Message"]]: + ) -> Union["types.Message", list["types.Message"]]: """Bound method *forward* of :obj:`~hydrogram.types.Message`. Use as a shortcut for: @@ -3176,7 +3177,7 @@ async def copy( caption: Optional[str] = None, message_thread_id: Optional[int] = None, parse_mode: Optional["enums.ParseMode"] = None, - caption_entities: Optional[List["types.MessageEntity"]] = None, + caption_entities: Optional[list["types.MessageEntity"]] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, schedule_date: Optional[datetime] = None, @@ -3187,7 +3188,7 @@ async def copy( "types.ReplyKeyboardRemove", "types.ForceReply", ] = object, - ) -> Union["types.Message", List["types.Message"]]: + ) -> Union["types.Message", list["types.Message"]]: """Bound method *copy* of :obj:`~hydrogram.types.Message`. Use as a shortcut for: diff --git a/hydrogram/types/messages_and_media/message_reactions.py b/hydrogram/types/messages_and_media/message_reactions.py index f10a41a11..f7784dbbd 100644 --- a/hydrogram/types/messages_and_media/message_reactions.py +++ b/hydrogram/types/messages_and_media/message_reactions.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import raw, types @@ -36,7 +36,7 @@ def __init__( self, *, client: "hydrogram.Client" = None, - reactions: Optional[List["types.Reaction"]] = None, + reactions: Optional[list["types.Reaction"]] = None, ): super().__init__(client) diff --git a/hydrogram/types/messages_and_media/photo.py b/hydrogram/types/messages_and_media/photo.py index 1eb2cd727..37ad358f4 100644 --- a/hydrogram/types/messages_and_media/photo.py +++ b/hydrogram/types/messages_and_media/photo.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import raw, types, utils @@ -73,7 +73,7 @@ def __init__( file_size: int, date: datetime, ttl_seconds: Optional[int] = None, - thumbs: Optional[List["types.Thumbnail"]] = None, + thumbs: Optional[list["types.Thumbnail"]] = None, ): super().__init__(client) @@ -89,7 +89,7 @@ def __init__( @staticmethod def _parse(client, photo: "raw.types.Photo", ttl_seconds: Optional[int] = None) -> "Photo": if isinstance(photo, raw.types.Photo): - photos: List[raw.types.PhotoSize] = [] + photos: list[raw.types.PhotoSize] = [] for p in photo.sizes: if isinstance(p, raw.types.PhotoSize): diff --git a/hydrogram/types/messages_and_media/poll.py b/hydrogram/types/messages_and_media/poll.py index b55961caf..e62f9483a 100644 --- a/hydrogram/types/messages_and_media/poll.py +++ b/hydrogram/types/messages_and_media/poll.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import enums, raw, types, utils @@ -82,7 +82,7 @@ def __init__( client: "hydrogram.Client" = None, id: str, question: str, - options: List["types.PollOption"], + options: list["types.PollOption"], total_voter_count: int, is_closed: bool, is_anonymous: Optional[bool] = None, @@ -91,7 +91,7 @@ def __init__( chosen_option_id: Optional[int] = None, correct_option_id: Optional[int] = None, explanation: Optional[str] = None, - explanation_entities: Optional[List["types.MessageEntity"]] = None, + explanation_entities: Optional[list["types.MessageEntity"]] = None, open_period: Optional[int] = None, close_date: Optional[datetime] = None, ): @@ -119,7 +119,7 @@ def _parse( ) -> "Poll": poll: raw.types.Poll = media_poll.poll poll_results: raw.types.PollResults = media_poll.results - results: List[raw.types.PollAnswerVoters] = poll_results.results + results: list[raw.types.PollAnswerVoters] = poll_results.results chosen_option_id = None correct_option_id = None diff --git a/hydrogram/types/messages_and_media/sticker.py b/hydrogram/types/messages_and_media/sticker.py index 566ced2e1..d3b10f103 100644 --- a/hydrogram/types/messages_and_media/sticker.py +++ b/hydrogram/types/messages_and_media/sticker.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import ClassVar, Dict, List, Optional, Type +from typing import ClassVar, Optional import hydrogram from hydrogram import raw, types, utils @@ -90,7 +90,7 @@ def __init__( date: Optional[datetime] = None, emoji: Optional[str] = None, set_name: Optional[str] = None, - thumbs: Optional[List["types.Thumbnail"]] = None, + thumbs: Optional[list["types.Thumbnail"]] = None, ): super().__init__(client) @@ -147,8 +147,8 @@ async def _get_sticker_set_name(invoke, input_sticker_set_id): async def _parse( client, sticker: "raw.types.Document", - document_attributes: Dict[ - Type["raw.base.DocumentAttribute"], "raw.base.DocumentAttribute" + document_attributes: dict[ + type["raw.base.DocumentAttribute"], "raw.base.DocumentAttribute" ], ) -> "Sticker": sticker_attributes = ( diff --git a/hydrogram/types/messages_and_media/thumbnail.py b/hydrogram/types/messages_and_media/thumbnail.py index af43a7b75..3b27fb31c 100644 --- a/hydrogram/types/messages_and_media/thumbnail.py +++ b/hydrogram/types/messages_and_media/thumbnail.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import raw @@ -73,7 +73,7 @@ def __init__( @staticmethod def _parse( client, media: Union["raw.types.Photo", "raw.types.Document"] - ) -> Optional[List["Thumbnail"]]: + ) -> Optional[list["Thumbnail"]]: if isinstance(media, raw.types.Photo): raw_thumbs = [i for i in media.sizes if isinstance(i, raw.types.PhotoSize)] raw_thumbs.sort(key=lambda p: p.size) diff --git a/hydrogram/types/messages_and_media/video.py b/hydrogram/types/messages_and_media/video.py index 9efd24416..c251285b4 100644 --- a/hydrogram/types/messages_and_media/video.py +++ b/hydrogram/types/messages_and_media/video.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import raw, types, utils @@ -83,7 +83,7 @@ def __init__( supports_streaming: Optional[bool] = None, ttl_seconds: Optional[int] = None, date: Optional[datetime] = None, - thumbs: Optional[List["types.Thumbnail"]] = None, + thumbs: Optional[list["types.Thumbnail"]] = None, ): super().__init__(client) diff --git a/hydrogram/types/messages_and_media/video_note.py b/hydrogram/types/messages_and_media/video_note.py index 835169073..d7f330b9d 100644 --- a/hydrogram/types/messages_and_media/video_note.py +++ b/hydrogram/types/messages_and_media/video_note.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import raw, types, utils @@ -64,7 +64,7 @@ def __init__( file_unique_id: str, length: int, duration: int, - thumbs: Optional[List["types.Thumbnail"]] = None, + thumbs: Optional[list["types.Thumbnail"]] = None, mime_type: Optional[str] = None, file_size: Optional[int] = None, date: Optional[datetime] = None, diff --git a/hydrogram/types/user_and_chats/chat.py b/hydrogram/types/user_and_chats/chat.py index fd045d889..903d8a125 100644 --- a/hydrogram/types/user_and_chats/chat.py +++ b/hydrogram/types/user_and_chats/chat.py @@ -17,8 +17,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . +from collections.abc import AsyncGenerator from datetime import datetime -from typing import AsyncGenerator, BinaryIO, List, Optional, Union +from typing import BinaryIO, Optional, Union import hydrogram from hydrogram import enums, raw, types, utils @@ -158,7 +159,7 @@ def __init__( title: Optional[str] = None, username: Optional[str] = None, active_usernames: Optional[str] = None, - usernames: Optional[List["types.Username"]] = None, + usernames: Optional[list["types.Username"]] = None, first_name: Optional[str] = None, last_name: Optional[str] = None, photo: "types.ChatPhoto" = None, @@ -171,7 +172,7 @@ def __init__( sticker_set_name: Optional[str] = None, can_set_sticker_set: Optional[bool] = None, members_count: Optional[int] = None, - restrictions: Optional[List["types.Restriction"]] = None, + restrictions: Optional[list["types.Restriction"]] = None, permissions: "types.ChatPermissions" = None, distance: Optional[int] = None, linked_chat: "types.Chat" = None, @@ -879,7 +880,7 @@ def get_members( async def add_members( self, - user_ids: Union[Union[int, str], List[Union[int, str]]], + user_ids: Union[Union[int, str], list[Union[int, str]]], forward_limit: int = 100, ) -> bool: """Bound method *add_members* of :obj:`~hydrogram.types.Chat`. diff --git a/hydrogram/types/user_and_chats/chat_admin_with_invite_links.py b/hydrogram/types/user_and_chats/chat_admin_with_invite_links.py index 46c9373c6..3f63a5645 100644 --- a/hydrogram/types/user_and_chats/chat_admin_with_invite_links.py +++ b/hydrogram/types/user_and_chats/chat_admin_with_invite_links.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import Dict, Optional +from typing import Optional import hydrogram from hydrogram import raw, types @@ -55,7 +55,7 @@ def __init__( def _parse( client: "hydrogram.Client", admin: "raw.types.ChatAdminWithInvites", - users: Optional[Dict[int, "raw.types.User"]] = None, + users: Optional[dict[int, "raw.types.User"]] = None, ) -> "ChatAdminWithInviteLinks": return ChatAdminWithInviteLinks( admin=types.User._parse(client, users[admin.admin_id]), diff --git a/hydrogram/types/user_and_chats/chat_event.py b/hydrogram/types/user_and_chats/chat_event.py index c6bc77338..fa36edc7d 100644 --- a/hydrogram/types/user_and_chats/chat_event.py +++ b/hydrogram/types/user_and_chats/chat_event.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -259,8 +259,8 @@ def __init__( async def _parse( client: "hydrogram.Client", event: "raw.base.ChannelAdminLogEvent", - users: List["raw.base.User"], - chats: List["raw.base.Chat"], + users: list["raw.base.User"], + chats: list["raw.base.Chat"], ): users = {i.id: i for i in users} chats = {i.id: i for i in chats} diff --git a/hydrogram/types/user_and_chats/chat_invite_link.py b/hydrogram/types/user_and_chats/chat_invite_link.py index d4d9e6635..02b4b2569 100644 --- a/hydrogram/types/user_and_chats/chat_invite_link.py +++ b/hydrogram/types/user_and_chats/chat_invite_link.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import Dict, Optional +from typing import Optional import hydrogram from hydrogram import raw, types, utils @@ -103,7 +103,7 @@ def __init__( def _parse( client: "hydrogram.Client", invite: "raw.base.ExportedChatInvite", - users: Optional[Dict[int, "raw.types.User"]] = None, + users: Optional[dict[int, "raw.types.User"]] = None, ) -> Optional["ChatInviteLink"]: if not isinstance(invite, raw.types.ChatInviteExported): return None diff --git a/hydrogram/types/user_and_chats/chat_join_request.py b/hydrogram/types/user_and_chats/chat_join_request.py index f8637a930..5cfdd8b9b 100644 --- a/hydrogram/types/user_and_chats/chat_join_request.py +++ b/hydrogram/types/user_and_chats/chat_join_request.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import Dict, Optional +from typing import Optional import hydrogram from hydrogram import raw, types, utils @@ -68,8 +68,8 @@ def __init__( def _parse( client: "hydrogram.Client", update: "raw.types.UpdateBotChatInviteRequester", - users: Dict[int, "raw.types.User"], - chats: Dict[int, "raw.types.Chat"], + users: dict[int, "raw.types.User"], + chats: dict[int, "raw.types.Chat"], ) -> "ChatJoinRequest": chat_id = utils.get_raw_peer_id(update.peer) diff --git a/hydrogram/types/user_and_chats/chat_joiner.py b/hydrogram/types/user_and_chats/chat_joiner.py index cf3c2d5ef..f15189bbb 100644 --- a/hydrogram/types/user_and_chats/chat_joiner.py +++ b/hydrogram/types/user_and_chats/chat_joiner.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import Dict, Optional +from typing import Optional import hydrogram from hydrogram import raw, types, utils @@ -67,7 +67,7 @@ def __init__( def _parse( client: "hydrogram.Client", joiner: "raw.base.ChatInviteImporter", - users: Dict[int, "raw.base.User"], + users: dict[int, "raw.base.User"], ) -> "ChatJoiner": return ChatJoiner( user=types.User._parse(client, users[joiner.user_id]), diff --git a/hydrogram/types/user_and_chats/chat_member.py b/hydrogram/types/user_and_chats/chat_member.py index f141f5b8b..268f97562 100644 --- a/hydrogram/types/user_and_chats/chat_member.py +++ b/hydrogram/types/user_and_chats/chat_member.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import Dict, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import enums, raw, types, utils @@ -111,8 +111,8 @@ def __init__( def _parse( client: "hydrogram.Client", member: Union["raw.base.ChatParticipant", "raw.base.ChannelParticipant"], - users: Dict[int, "raw.base.User"], - chats: Dict[int, "raw.base.Chat"], + users: dict[int, "raw.base.User"], + chats: dict[int, "raw.base.Chat"], ) -> "ChatMember": # Chat participants if isinstance(member, raw.types.ChatParticipant): diff --git a/hydrogram/types/user_and_chats/chat_member_updated.py b/hydrogram/types/user_and_chats/chat_member_updated.py index 502fe6e15..2c51d6135 100644 --- a/hydrogram/types/user_and_chats/chat_member_updated.py +++ b/hydrogram/types/user_and_chats/chat_member_updated.py @@ -18,7 +18,7 @@ # along with Hydrogram. If not, see . from datetime import datetime -from typing import Dict, Union +from typing import Union import hydrogram from hydrogram import raw, types, utils @@ -73,8 +73,8 @@ def __init__( def _parse( client: "hydrogram.Client", update: Union["raw.types.UpdateChatParticipant", "raw.types.UpdateChannelParticipant"], - users: Dict[int, "raw.types.User"], - chats: Dict[int, "raw.types.Chat"], + users: dict[int, "raw.types.User"], + chats: dict[int, "raw.types.Chat"], ) -> "ChatMemberUpdated": chat_id = getattr(update, "chat_id", None) or getattr(update, "channel_id") diff --git a/hydrogram/types/user_and_chats/chat_preview.py b/hydrogram/types/user_and_chats/chat_preview.py index 50d73e23e..1fbe48fcf 100644 --- a/hydrogram/types/user_and_chats/chat_preview.py +++ b/hydrogram/types/user_and_chats/chat_preview.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import raw, types @@ -52,7 +52,7 @@ def __init__( type: str, members_count: int, photo: "types.Photo" = None, - members: Optional[List["types.User"]] = None, + members: Optional[list["types.User"]] = None, ): super().__init__(client) diff --git a/hydrogram/types/user_and_chats/chat_reactions.py b/hydrogram/types/user_and_chats/chat_reactions.py index 82d72593d..e8287b238 100644 --- a/hydrogram/types/user_and_chats/chat_reactions.py +++ b/hydrogram/types/user_and_chats/chat_reactions.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import raw, types @@ -43,7 +43,7 @@ def __init__( client: "hydrogram.Client" = None, all_are_enabled: Optional[bool] = None, allow_custom_emoji: Optional[bool] = None, - reactions: Optional[List["types.Reaction"]] = None, + reactions: Optional[list["types.Reaction"]] = None, ): super().__init__(client) diff --git a/hydrogram/types/user_and_chats/user.py b/hydrogram/types/user_and_chats/user.py index cd899d164..d22d7a1d1 100644 --- a/hydrogram/types/user_and_chats/user.py +++ b/hydrogram/types/user_and_chats/user.py @@ -19,7 +19,7 @@ import html from datetime import datetime -from typing import List, Optional +from typing import Optional import hydrogram from hydrogram import enums, raw, types, utils @@ -174,13 +174,13 @@ def __init__( next_offline_date: Optional[datetime] = None, username: Optional[str] = None, active_usernames: Optional[str] = None, - usernames: Optional[List["types.Username"]] = None, + usernames: Optional[list["types.Username"]] = None, language_code: Optional[str] = None, emoji_status: Optional["types.EmojiStatus"] = None, dc_id: Optional[int] = None, phone_number: Optional[str] = None, photo: "types.ChatPhoto" = None, - restrictions: Optional[List["types.Restriction"]] = None, + restrictions: Optional[list["types.Restriction"]] = None, ): super().__init__(client) diff --git a/hydrogram/types/user_and_chats/video_chat_members_invited.py b/hydrogram/types/user_and_chats/video_chat_members_invited.py index 78c16f9b3..e2b33723c 100644 --- a/hydrogram/types/user_and_chats/video_chat_members_invited.py +++ b/hydrogram/types/user_and_chats/video_chat_members_invited.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Hydrogram. If not, see . -from typing import Dict, List from hydrogram import raw, types from hydrogram.types.object import Object @@ -32,7 +31,7 @@ class VideoChatMembersInvited(Object): New members that were invited to the voice chat. """ - def __init__(self, *, users: List["types.User"]): + def __init__(self, *, users: list["types.User"]): super().__init__() self.users = users @@ -41,7 +40,7 @@ def __init__(self, *, users: List["types.User"]): def _parse( client, action: "raw.types.MessageActionInviteToGroupCall", - users: Dict[int, "raw.types.User"], + users: dict[int, "raw.types.User"], ) -> "VideoChatMembersInvited": users = [types.User._parse(client, users[i]) for i in action.users] diff --git a/hydrogram/utils.py b/hydrogram/utils.py index f0f50ab22..2baa1d29f 100644 --- a/hydrogram/utils.py +++ b/hydrogram/utils.py @@ -26,7 +26,7 @@ from concurrent.futures.thread import ThreadPoolExecutor from datetime import datetime, timezone from getpass import getpass -from typing import Dict, List, Optional, Union +from typing import Optional, Union import hydrogram from hydrogram import enums, raw, types @@ -86,7 +86,7 @@ def get_input_media_from_file_id( async def parse_messages( client, messages: "raw.types.messages.Messages", replies: int = 1 -) -> List["types.Message"]: +) -> list["types.Message"]: users = {i.id: i for i in messages.users} chats = {i.id: i for i in messages.chats} topics = {i.id: i for i in messages.topics} if hasattr(messages, "topics") else None @@ -126,7 +126,7 @@ async def parse_messages( return types.List(parsed_messages) -def parse_deleted_messages(client, update) -> List["types.Message"]: +def parse_deleted_messages(client, update) -> list["types.Message"]: messages = update.messages channel_id = getattr(update, "channel_id", None) @@ -319,8 +319,8 @@ async def parse_text_entities( client: "hydrogram.Client", text: str, parse_mode: enums.ParseMode, - entities: List["types.MessageEntity"], -) -> Dict[str, Union[str, List[raw.base.MessageEntity]]]: + entities: list["types.MessageEntity"], +) -> dict[str, Union[str, list[raw.base.MessageEntity]]]: if entities: # Inject the client instance because parsing user mentions requires it for entity in entities: diff --git a/pyproject.toml b/pyproject.toml index 23f2232ac..7200b670e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,14 +3,10 @@ name = "Hydrogram" dynamic = ["version"] description = "Sleek, advanced, and asynchronous Telegram MTProto API framework in Python, designed for fluid user and bot interactions." authors = [{ name = "Amano LLC", email = "contact@amanoteam.com" }] -dependencies = [ - "pyaes==1.6.1", - "pysocks==1.7.1", - "aiosqlite>=0.19.0", -] +dependencies = ["pyaes==1.6.1", "pysocks==1.7.1", "aiosqlite>=0.19.0"] readme = "README.md" license = "LGPL-3.0-or-later" -requires-python = ">=3.8" +requires-python = ">=3.9" classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", @@ -98,7 +94,7 @@ package = "hydrogram" [tool.ruff] line-length = 99 -target-version = "py38" +target-version = "py39" select = [ "I", # isort "E", # pycodestyle From afcda80f2b01d61e3bd9fa9ddec3d983c621122e Mon Sep 17 00:00:00 2001 From: Hitalo Date: Mon, 4 Dec 2023 19:51:16 -0300 Subject: [PATCH 2/5] chore(cherry-picker): changes ruff python version --- cherry-pick-pyro.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cherry-pick-pyro.sh b/cherry-pick-pyro.sh index 82684bf8e..5016b26e6 100755 --- a/cherry-pick-pyro.sh +++ b/cherry-pick-pyro.sh @@ -8,7 +8,7 @@ ORIGIN_BRANCH="master" RUFF_TOML=$(cat < Date: Mon, 4 Dec 2023 19:54:36 -0300 Subject: [PATCH 3/5] chore(ci): removes python 3.8 from build test --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index f6269d7a4..96a04c665 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -10,7 +10,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 From 8c7b24c029f89b442150be073da6e865033e6721 Mon Sep 17 00:00:00 2001 From: Hitalo Date: Mon, 4 Dec 2023 20:37:11 -0300 Subject: [PATCH 4/5] chore(pre-commit): updates ruff to 0.1.7 --- .pre-commit-config.yaml | 2 +- compiler/api/compiler.py | 12 +- compiler/errors/compiler.py | 26 +-- hydrogram/client.py | 44 ++-- .../methods/decorators/on_callback_query.py | 10 +- .../decorators/on_chat_join_request.py | 10 +- .../decorators/on_chat_member_updated.py | 10 +- .../decorators/on_chosen_inline_result.py | 10 +- .../methods/decorators/on_deleted_messages.py | 10 +- .../methods/decorators/on_edited_message.py | 10 +- .../methods/decorators/on_inline_query.py | 10 +- hydrogram/methods/decorators/on_message.py | 10 +- hydrogram/methods/decorators/on_poll.py | 10 +- .../methods/decorators/on_user_status.py | 10 +- hydrogram/methods/messages/download_media.py | 20 +- hydrogram/parser/markdown.py | 26 +-- hydrogram/types/user_and_chats/chat.py | 6 +- .../types/user_and_chats/chat_permissions.py | 14 +- hydrogram/types/user_and_chats/user.py | 6 +- tests/parser/test_html.py | 218 ++++++++---------- 20 files changed, 208 insertions(+), 266 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f99f2d14e..56316e123 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: - id: check-yaml - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.6 + rev: v0.1.7 hooks: - id: ruff-format - id: ruff diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index c6a9d4c6d..1f74613ad 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -428,13 +428,11 @@ def start(format: bool = False): f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0" ) - write_flags = "\n ".join( - [ - f"{arg_name} = 0", - "\n ".join(write_flags), - f"b.write(Int({arg_name}))\n ", - ] - ) + write_flags = "\n ".join([ + f"{arg_name} = 0", + "\n ".join(write_flags), + f"b.write(Int({arg_name}))\n ", + ]) write_types += write_flags read_types += f"\n {arg_name} = Int.read(b)\n " diff --git a/compiler/errors/compiler.py b/compiler/errors/compiler.py index ff83a71a8..c54837e79 100644 --- a/compiler/errors/compiler.py +++ b/compiler/errors/compiler.py @@ -76,9 +76,9 @@ def start(): reader = csv.reader(f_csv, delimiter="\t") super_class = caml(name) - name = " ".join( - [str(i.capitalize()) for i in re.sub(r"_", " ", name).lower().split(" ")] - ) + name = " ".join([ + str(i.capitalize()) for i in re.sub(r"_", " ", name).lower().split(" ") + ]) sub_classes = [] @@ -116,17 +116,15 @@ def start(): super_class=super_class, code=code, docstring=f'"""{name}"""', - sub_classes="".join( - [ - sub_class_template.format( - sub_class=k[0], - super_class=super_class, - id=f'"{k[1]}"', - docstring=f'"""{k[2]}"""', - ) - for k in sub_classes - ] - ), + sub_classes="".join([ + sub_class_template.format( + sub_class=k[0], + super_class=super_class, + id=f'"{k[1]}"', + docstring=f'"""{k[2]}"""', + ) + for k in sub_classes + ]), ) f_class.write(class_template) diff --git a/hydrogram/client.py b/hydrogram/client.py index 708eee885..9d000a20b 100644 --- a/hydrogram/client.py +++ b/hydrogram/client.py @@ -557,12 +557,10 @@ async def handle_updates(self, updates): self.last_update_time = datetime.now() if isinstance(updates, (raw.types.Updates, raw.types.UpdatesCombined)): - is_min = any( - ( - await self.fetch_peers(updates.users), - await self.fetch_peers(updates.chats), - ) - ) + is_min = any(( + await self.fetch_peers(updates.users), + await self.fetch_peers(updates.chats), + )) users = {u.id: u for u in updates.users} chats = {c.id: c for c in updates.chats} @@ -618,17 +616,15 @@ async def handle_updates(self, updates): ) if diff.new_messages: - self.dispatcher.updates_queue.put_nowait( - ( - raw.types.UpdateNewMessage( - message=diff.new_messages[0], - pts=updates.pts, - pts_count=updates.pts_count, - ), - {u.id: u for u in diff.users}, - {c.id: c for c in diff.chats}, - ) - ) + self.dispatcher.updates_queue.put_nowait(( + raw.types.UpdateNewMessage( + message=diff.new_messages[0], + pts=updates.pts, + pts_count=updates.pts_count, + ), + {u.id: u for u in diff.users}, + {c.id: c for c in diff.chats}, + )) elif diff.other_updates: # The other_updates list can be empty self.dispatcher.updates_queue.put_nowait((diff.other_updates[0], {}, {})) elif isinstance(updates, raw.types.UpdateShort): @@ -639,14 +635,12 @@ async def handle_updates(self, updates): async def load_session(self): await self.storage.open() - session_empty = any( - [ - await self.storage.test_mode() is None, - await self.storage.auth_key() is None, - await self.storage.user_id() is None, - await self.storage.is_bot() is None, - ] - ) + session_empty = any([ + await self.storage.test_mode() is None, + await self.storage.auth_key() is None, + await self.storage.user_id() is None, + await self.storage.is_bot() is None, + ]) if session_empty: if not self.api_id or not self.api_hash: diff --git a/hydrogram/methods/decorators/on_callback_query.py b/hydrogram/methods/decorators/on_callback_query.py index 6b2d8d2a2..500a26bd4 100644 --- a/hydrogram/methods/decorators/on_callback_query.py +++ b/hydrogram/methods/decorators/on_callback_query.py @@ -46,12 +46,10 @@ def decorator(func: Callable) -> Callable: if not hasattr(func, "handlers"): func.handlers = [] - func.handlers.append( - ( - hydrogram.handlers.CallbackQueryHandler(func, self), - group if filters is None else filters, - ) - ) + func.handlers.append(( + hydrogram.handlers.CallbackQueryHandler(func, self), + group if filters is None else filters, + )) return func diff --git a/hydrogram/methods/decorators/on_chat_join_request.py b/hydrogram/methods/decorators/on_chat_join_request.py index 873cb2f76..9a225a6c1 100644 --- a/hydrogram/methods/decorators/on_chat_join_request.py +++ b/hydrogram/methods/decorators/on_chat_join_request.py @@ -45,12 +45,10 @@ def decorator(func: Callable) -> Callable: if not hasattr(func, "handlers"): func.handlers = [] - func.handlers.append( - ( - hydrogram.handlers.ChatJoinRequestHandler(func, self), - group if filters is None else filters, - ) - ) + func.handlers.append(( + hydrogram.handlers.ChatJoinRequestHandler(func, self), + group if filters is None else filters, + )) return func diff --git a/hydrogram/methods/decorators/on_chat_member_updated.py b/hydrogram/methods/decorators/on_chat_member_updated.py index afc4c9d18..03a5c07d3 100644 --- a/hydrogram/methods/decorators/on_chat_member_updated.py +++ b/hydrogram/methods/decorators/on_chat_member_updated.py @@ -45,12 +45,10 @@ def decorator(func: Callable) -> Callable: if not hasattr(func, "handlers"): func.handlers = [] - func.handlers.append( - ( - hydrogram.handlers.ChatMemberUpdatedHandler(func, self), - group if filters is None else filters, - ) - ) + func.handlers.append(( + hydrogram.handlers.ChatMemberUpdatedHandler(func, self), + group if filters is None else filters, + )) return func diff --git a/hydrogram/methods/decorators/on_chosen_inline_result.py b/hydrogram/methods/decorators/on_chosen_inline_result.py index c0fc7c158..a30b24dc2 100644 --- a/hydrogram/methods/decorators/on_chosen_inline_result.py +++ b/hydrogram/methods/decorators/on_chosen_inline_result.py @@ -48,12 +48,10 @@ def decorator(func: Callable) -> Callable: if not hasattr(func, "handlers"): func.handlers = [] - func.handlers.append( - ( - hydrogram.handlers.ChosenInlineResultHandler(func, self), - group if filters is None else filters, - ) - ) + func.handlers.append(( + hydrogram.handlers.ChosenInlineResultHandler(func, self), + group if filters is None else filters, + )) return func diff --git a/hydrogram/methods/decorators/on_deleted_messages.py b/hydrogram/methods/decorators/on_deleted_messages.py index e2cb62bc4..7d06530a4 100644 --- a/hydrogram/methods/decorators/on_deleted_messages.py +++ b/hydrogram/methods/decorators/on_deleted_messages.py @@ -46,12 +46,10 @@ def decorator(func: Callable) -> Callable: if not hasattr(func, "handlers"): func.handlers = [] - func.handlers.append( - ( - hydrogram.handlers.DeletedMessagesHandler(func, self), - group if filters is None else filters, - ) - ) + func.handlers.append(( + hydrogram.handlers.DeletedMessagesHandler(func, self), + group if filters is None else filters, + )) return func diff --git a/hydrogram/methods/decorators/on_edited_message.py b/hydrogram/methods/decorators/on_edited_message.py index 510c4a8d5..350bcea2c 100644 --- a/hydrogram/methods/decorators/on_edited_message.py +++ b/hydrogram/methods/decorators/on_edited_message.py @@ -46,12 +46,10 @@ def decorator(func: Callable) -> Callable: if not hasattr(func, "handlers"): func.handlers = [] - func.handlers.append( - ( - hydrogram.handlers.EditedMessageHandler(func, self), - group if filters is None else filters, - ) - ) + func.handlers.append(( + hydrogram.handlers.EditedMessageHandler(func, self), + group if filters is None else filters, + )) return func diff --git a/hydrogram/methods/decorators/on_inline_query.py b/hydrogram/methods/decorators/on_inline_query.py index f59239108..b58221ec6 100644 --- a/hydrogram/methods/decorators/on_inline_query.py +++ b/hydrogram/methods/decorators/on_inline_query.py @@ -46,12 +46,10 @@ def decorator(func: Callable) -> Callable: if not hasattr(func, "handlers"): func.handlers = [] - func.handlers.append( - ( - hydrogram.handlers.InlineQueryHandler(func, self), - group if filters is None else filters, - ) - ) + func.handlers.append(( + hydrogram.handlers.InlineQueryHandler(func, self), + group if filters is None else filters, + )) return func diff --git a/hydrogram/methods/decorators/on_message.py b/hydrogram/methods/decorators/on_message.py index 3261c49cc..b65d838b7 100644 --- a/hydrogram/methods/decorators/on_message.py +++ b/hydrogram/methods/decorators/on_message.py @@ -46,12 +46,10 @@ def decorator(func: Callable) -> Callable: if not hasattr(func, "handlers"): func.handlers = [] - func.handlers.append( - ( - hydrogram.handlers.MessageHandler(func, self), - group if filters is None else filters, - ) - ) + func.handlers.append(( + hydrogram.handlers.MessageHandler(func, self), + group if filters is None else filters, + )) return func diff --git a/hydrogram/methods/decorators/on_poll.py b/hydrogram/methods/decorators/on_poll.py index a67a703b3..770ccb276 100644 --- a/hydrogram/methods/decorators/on_poll.py +++ b/hydrogram/methods/decorators/on_poll.py @@ -46,12 +46,10 @@ def decorator(func: Callable) -> Callable: if not hasattr(func, "handlers"): func.handlers = [] - func.handlers.append( - ( - hydrogram.handlers.PollHandler(func, self), - group if filters is None else filters, - ) - ) + func.handlers.append(( + hydrogram.handlers.PollHandler(func, self), + group if filters is None else filters, + )) return func diff --git a/hydrogram/methods/decorators/on_user_status.py b/hydrogram/methods/decorators/on_user_status.py index 87c1e3394..d58145d2b 100644 --- a/hydrogram/methods/decorators/on_user_status.py +++ b/hydrogram/methods/decorators/on_user_status.py @@ -44,12 +44,10 @@ def decorator(func: Callable) -> Callable: if not hasattr(func, "handlers"): func.handlers = [] - func.handlers.append( - ( - hydrogram.handlers.UserStatusHandler(func, self), - group if filters is None else filters, - ) - ) + func.handlers.append(( + hydrogram.handlers.UserStatusHandler(func, self), + group if filters is None else filters, + )) return func diff --git a/hydrogram/methods/messages/download_media.py b/hydrogram/methods/messages/download_media.py index 4865b6889..ced114aea 100644 --- a/hydrogram/methods/messages/download_media.py +++ b/hydrogram/methods/messages/download_media.py @@ -180,17 +180,15 @@ async def progress(current, total): file_name = f'{FileType(file_id_obj.file_type).name.lower()}_{(date or datetime.now()).strftime("%Y-%m-%d_%H-%M-%S")}_{self.rnd_id()}{extension}' - downloader = self.handle_download( - ( - file_id_obj, - directory, - file_name, - in_memory, - file_size, - progress, - progress_args, - ) - ) + downloader = self.handle_download(( + file_id_obj, + directory, + file_name, + in_memory, + file_size, + progress, + progress_args, + )) if block: return await downloader diff --git a/hydrogram/parser/markdown.py b/hydrogram/parser/markdown.py index 358837b9c..ad799a39a 100644 --- a/hydrogram/parser/markdown.py +++ b/hydrogram/parser/markdown.py @@ -37,23 +37,21 @@ MARKDOWN_RE = re.compile( r"({d})|\[(.+?)\]\((.+?)\)".format( - d="|".join( - [ - "".join(i) + d="|".join([ + "".join(i) + for i in [ + [rf"\{j}" for j in i] for i in [ - [rf"\{j}" for j in i] - for i in [ - PRE_DELIM, - CODE_DELIM, - STRIKE_DELIM, - UNDERLINE_DELIM, - ITALIC_DELIM, - BOLD_DELIM, - SPOILER_DELIM, - ] + PRE_DELIM, + CODE_DELIM, + STRIKE_DELIM, + UNDERLINE_DELIM, + ITALIC_DELIM, + BOLD_DELIM, + SPOILER_DELIM, ] ] - ) + ]) ) ) diff --git a/hydrogram/types/user_and_chats/chat.py b/hydrogram/types/user_and_chats/chat.py index 903d8a125..75594d0b9 100644 --- a/hydrogram/types/user_and_chats/chat.py +++ b/hydrogram/types/user_and_chats/chat.py @@ -230,9 +230,9 @@ def _parse_user_chat(client, user: raw.types.User) -> "Chat": is_fake=getattr(user, "fake", None), is_support=getattr(user, "support", None), username=user.usernames[0].username if user.usernames else user.username, - active_usernames=types.List( - [username.username for username in user.usernames if username.active] - ) + active_usernames=types.List([ + username.username for username in user.usernames if username.active + ]) or None, usernames=types.List([types.Username._parse(r) for r in user.usernames]) or None, first_name=user.first_name, diff --git a/hydrogram/types/user_and_chats/chat_permissions.py b/hydrogram/types/user_and_chats/chat_permissions.py index 453878a10..5c9305358 100644 --- a/hydrogram/types/user_and_chats/chat_permissions.py +++ b/hydrogram/types/user_and_chats/chat_permissions.py @@ -95,14 +95,12 @@ def _parse(denied_permissions: "raw.base.ChatBannedRights") -> "ChatPermissions" return ChatPermissions( can_send_messages=not denied_permissions.send_messages, can_send_media_messages=not denied_permissions.send_media, - can_send_other_messages=any( - [ - not denied_permissions.send_stickers, - not denied_permissions.send_gifs, - not denied_permissions.send_games, - not denied_permissions.send_inline, - ] - ), + can_send_other_messages=any([ + not denied_permissions.send_stickers, + not denied_permissions.send_gifs, + not denied_permissions.send_games, + not denied_permissions.send_inline, + ]), can_add_web_page_previews=not denied_permissions.embed_links, can_send_polls=not denied_permissions.send_polls, can_change_info=not denied_permissions.change_info, diff --git a/hydrogram/types/user_and_chats/user.py b/hydrogram/types/user_and_chats/user.py index d22d7a1d1..89fd089f2 100644 --- a/hydrogram/types/user_and_chats/user.py +++ b/hydrogram/types/user_and_chats/user.py @@ -245,9 +245,9 @@ def _parse(client, user: "raw.base.User") -> Optional["User"]: last_name=user.last_name, **User._parse_status(user.status, user.bot), username=user.usernames[0].username if user.usernames else user.username, - active_usernames=types.List( - [username.username for username in user.usernames if username.active] - ) + active_usernames=types.List([ + username.username for username in user.usernames if username.active + ]) or None, usernames=types.List([types.Username._parse(r) for r in user.usernames]) or None, language_code=user.lang_code, diff --git a/tests/parser/test_html.py b/tests/parser/test_html.py index 83c65d635..f77cab2fc 100644 --- a/tests/parser/test_html.py +++ b/tests/parser/test_html.py @@ -28,13 +28,11 @@ def test_html_unparse_bold(): expected = "bold" text = "bold" - entities = hydrogram.types.List( - [ - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.BOLD, offset=0, length=4 - ) - ] - ) + entities = hydrogram.types.List([ + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.BOLD, offset=0, length=4 + ) + ]) assert HTML.unparse(text=text, entities=entities) == expected @@ -42,13 +40,11 @@ def test_html_unparse_bold(): def test_html_unparse_italic(): expected = "italic" text = "italic" - entities = hydrogram.types.List( - [ - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.ITALIC, offset=0, length=6 - ) - ] - ) + entities = hydrogram.types.List([ + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.ITALIC, offset=0, length=6 + ) + ]) assert HTML.unparse(text=text, entities=entities) == expected @@ -56,13 +52,11 @@ def test_html_unparse_italic(): def test_html_unparse_underline(): expected = "underline" text = "underline" - entities = hydrogram.types.List( - [ - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.UNDERLINE, offset=0, length=9 - ) - ] - ) + entities = hydrogram.types.List([ + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.UNDERLINE, offset=0, length=9 + ) + ]) assert HTML.unparse(text=text, entities=entities) == expected @@ -70,13 +64,11 @@ def test_html_unparse_underline(): def test_html_unparse_strike(): expected = "strike" text = "strike" - entities = hydrogram.types.List( - [ - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.STRIKETHROUGH, offset=0, length=6 - ) - ] - ) + entities = hydrogram.types.List([ + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.STRIKETHROUGH, offset=0, length=6 + ) + ]) assert HTML.unparse(text=text, entities=entities) == expected @@ -84,13 +76,11 @@ def test_html_unparse_strike(): def test_html_unparse_spoiler(): expected = "spoiler" text = "spoiler" - entities = hydrogram.types.List( - [ - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.SPOILER, offset=0, length=7 - ) - ] - ) + entities = hydrogram.types.List([ + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.SPOILER, offset=0, length=7 + ) + ]) assert HTML.unparse(text=text, entities=entities) == expected @@ -98,16 +88,14 @@ def test_html_unparse_spoiler(): def test_html_unparse_url(): expected = 'URL' text = "URL" - entities = hydrogram.types.List( - [ - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.TEXT_LINK, - offset=0, - length=3, - url="https://hydrogram.amanoteam.com/", - ) - ] - ) + entities = hydrogram.types.List([ + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.TEXT_LINK, + offset=0, + length=3, + url="https://hydrogram.amanoteam.com/", + ) + ]) assert HTML.unparse(text=text, entities=entities) == expected @@ -115,13 +103,11 @@ def test_html_unparse_url(): def test_html_unparse_code(): expected = "code" text = "code" - entities = hydrogram.types.List( - [ - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.CODE, offset=0, length=4 - ) - ] - ) + entities = hydrogram.types.List([ + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.CODE, offset=0, length=4 + ) + ]) assert HTML.unparse(text=text, entities=entities) == expected @@ -133,16 +119,14 @@ def test_html_unparse_pre(): text = """for i in range(10): print(i)""" - entities = hydrogram.types.List( - [ - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.PRE, - offset=0, - length=32, - language="python", - ) - ] - ) + entities = hydrogram.types.List([ + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.PRE, + offset=0, + length=32, + language="python", + ) + ]) assert HTML.unparse(text=text, entities=entities) == expected @@ -153,47 +137,45 @@ def test_html_unparse_mixed(): "eeeeeeeeeeffffffffffgggggggggghhhhhhhhhh" ) text = "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhh" - entities = hydrogram.types.List( - [ - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.BOLD, offset=0, length=14 - ), - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.ITALIC, offset=7, length=7 - ), - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.UNDERLINE, offset=10, length=4 - ), - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.UNDERLINE, offset=14, length=9 - ), - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.ITALIC, offset=14, length=9 - ), - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.UNDERLINE, offset=23, length=10 - ), - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.STRIKETHROUGH, - offset=30, - length=3, - ), - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.STRIKETHROUGH, - offset=33, - length=10, - ), - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.SPOILER, offset=38, length=5 - ), - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.SPOILER, offset=43, length=10 - ), - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.CODE, offset=57, length=10 - ), - ] - ) + entities = hydrogram.types.List([ + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.BOLD, offset=0, length=14 + ), + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.ITALIC, offset=7, length=7 + ), + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.UNDERLINE, offset=10, length=4 + ), + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.UNDERLINE, offset=14, length=9 + ), + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.ITALIC, offset=14, length=9 + ), + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.UNDERLINE, offset=23, length=10 + ), + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.STRIKETHROUGH, + offset=30, + length=3, + ), + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.STRIKETHROUGH, + offset=33, + length=10, + ), + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.SPOILER, offset=38, length=5 + ), + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.SPOILER, offset=43, length=10 + ), + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.CODE, offset=57, length=10 + ), + ]) assert HTML.unparse(text=text, entities=entities) == expected @@ -201,13 +183,11 @@ def test_html_unparse_mixed(): def test_html_unparse_escaped(): expected = "<b>bold</b>" text = "bold" - entities = hydrogram.types.List( - [ - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.BOLD, offset=0, length=11 - ) - ] - ) + entities = hydrogram.types.List([ + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.BOLD, offset=0, length=11 + ) + ]) assert HTML.unparse(text=text, entities=entities) == expected @@ -215,16 +195,14 @@ def test_html_unparse_escaped(): def test_html_unparse_escaped_nested(): expected = "<b>bold <u>underline</u> bold</b>" text = "bold underline bold" - entities = hydrogram.types.List( - [ - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.BOLD, offset=0, length=33 - ), - hydrogram.types.MessageEntity( - type=hydrogram.enums.MessageEntityType.UNDERLINE, offset=8, length=16 - ), - ] - ) + entities = hydrogram.types.List([ + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.BOLD, offset=0, length=33 + ), + hydrogram.types.MessageEntity( + type=hydrogram.enums.MessageEntityType.UNDERLINE, offset=8, length=16 + ), + ]) assert HTML.unparse(text=text, entities=entities) == expected From 0f1b558cd86c1935daa5085bcbbc1f1e4fc61dc9 Mon Sep 17 00:00:00 2001 From: Alisson Lauffer Date: Tue, 5 Dec 2023 02:02:06 -0300 Subject: [PATCH 5/5] chore(pyproject): remove Python 3.8 classifier --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7200b670e..3c5eb416a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,6 @@ classifiers = [ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11",