Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: check-yaml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.4
rev: v0.1.7
hooks:
- id: ruff-format
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion cherry-pick-pyro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ORIGIN_BRANCH="master"
RUFF_TOML=$(cat <<EOF
[tool.ruff]
line-length = 99
target-version = "py38"
target-version = "py39"
select = [
"I", # isort
"E", # pycodestyle
Expand Down
16 changes: 7 additions & 9 deletions compiler/api/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 "
Expand Down
26 changes: 12 additions & 14 deletions compiler/errors/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down Expand Up @@ -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)
Expand Down
49 changes: 22 additions & 27 deletions hydrogram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
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
from importlib import import_module
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
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -556,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}
Expand Down Expand Up @@ -617,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):
Expand All @@ -638,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:
Expand Down
4 changes: 2 additions & 2 deletions hydrogram/errors/rpc_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions hydrogram/file_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions hydrogram/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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__(
Expand Down Expand Up @@ -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__(
Expand Down
4 changes: 2 additions & 2 deletions hydrogram/handlers/deleted_messages_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Hydrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Callable, List
from typing import Callable

import hydrogram
from hydrogram.filters import Filter
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion hydrogram/methods/bots/answer_inline_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Hydrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Iterable
from collections.abc import Iterable

import hydrogram
from hydrogram import raw, types
Expand Down
3 changes: 1 addition & 2 deletions hydrogram/methods/bots/get_bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Hydrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import List

import hydrogram
from hydrogram import raw, types
Expand All @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions hydrogram/methods/bots/get_game_high_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Hydrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import List, Optional, Union
from typing import Optional, Union

import hydrogram
from hydrogram import raw, types
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions hydrogram/methods/bots/set_bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Hydrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import List

import hydrogram
from hydrogram import raw, types
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions hydrogram/methods/chats/add_chat_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Hydrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import List, Union
from typing import Union

import hydrogram
from hydrogram import raw
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions hydrogram/methods/chats/archive_chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Hydrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import List, Union
from typing import Union

import hydrogram
from hydrogram import raw
Expand All @@ -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.

Expand Down
Loading