From 12a7336ea31deafbe7dfba57dd2062b9c07521e8 Mon Sep 17 00:00:00 2001 From: Sergio-prog Date: Tue, 17 Oct 2023 14:19:38 +0300 Subject: [PATCH 1/2] Template for Python <3.10 --- .../db/db_api/storages/basestorage/storage.py | 8 ++++---- aiogram_bot_template/filters/chat_type.py | 3 ++- aiogram_bot_template/filters/text.py | 6 ++++-- aiogram_bot_template/keyboards/inline/consts.py | 8 ++++---- poetry.lock | 6 +++--- pyproject.toml | 16 ++++++++-------- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/aiogram_bot_template/db/db_api/storages/basestorage/storage.py b/aiogram_bot_template/db/db_api/storages/basestorage/storage.py index 295ef54e..8e998ce3 100644 --- a/aiogram_bot_template/db/db_api/storages/basestorage/storage.py +++ b/aiogram_bot_template/db/db_api/storages/basestorage/storage.py @@ -1,5 +1,5 @@ import typing -from typing import Any, Optional, TypeVar +from typing import Any, Optional, TypeVar, Union T = TypeVar("T") @@ -32,7 +32,7 @@ class RawConnection: async def _fetch( self, sql: str, - params: Optional[tuple[Any, ...] | list[tuple[Any, ...]]] = None, + params: Optional[Union[tuple[Any, ...], list[tuple[Any, ...]]]] = None, con: Optional[Any] = None, ) -> MultipleQueryResults: raise NotImplementedError @@ -40,7 +40,7 @@ async def _fetch( async def _fetchrow( self, sql: str, - params: Optional[tuple[Any, ...] | list[tuple[Any, ...]]] = None, + params: Optional[Union[tuple[Any, ...], list[tuple[Any, ...]]]] = None, con: Optional[Any] = None, ) -> SingleQueryResult: raise NotImplementedError @@ -48,7 +48,7 @@ async def _fetchrow( async def _execute( self, sql: str, - params: Optional[tuple[Any, ...] | list[tuple[Any, ...]]] = None, + params: Optional[Union[tuple[Any, ...], list[tuple[Any, ...]]]] = None, con: Optional[Any] = None, ) -> None: raise NotImplementedError diff --git a/aiogram_bot_template/filters/chat_type.py b/aiogram_bot_template/filters/chat_type.py index aadabdc6..1c31f027 100644 --- a/aiogram_bot_template/filters/chat_type.py +++ b/aiogram_bot_template/filters/chat_type.py @@ -1,11 +1,12 @@ import typing +from typing import Union from aiogram.filters import BaseFilter from aiogram.types import Message class ChatTypeFilter(BaseFilter): - def __init__(self, chat_type: str | typing.Sequence[str]): + def __init__(self, chat_type: Union[str, typing.Sequence[str]]): self.chat_type = chat_type async def __call__(self, message: Message) -> bool: diff --git a/aiogram_bot_template/filters/text.py b/aiogram_bot_template/filters/text.py index 5349d028..aaffeb09 100644 --- a/aiogram_bot_template/filters/text.py +++ b/aiogram_bot_template/filters/text.py @@ -1,15 +1,17 @@ +from typing import Union + from aiogram.filters import BaseFilter from aiogram.types import CallbackQuery, Message class TextFilter(BaseFilter): - def __init__(self, text: str | list[str]): + def __init__(self, text: Union[str, list[str]]): if isinstance(text, str): self.text = [text] else: self.text = text - async def __call__(self, obj: Message | CallbackQuery) -> bool: + async def __call__(self, obj: Union[Message, CallbackQuery]) -> bool: if isinstance(obj, Message): txt = obj.text or obj.caption return any(i == txt for i in self.text) diff --git a/aiogram_bot_template/keyboards/inline/consts.py b/aiogram_bot_template/keyboards/inline/consts.py index 9f404e0c..a9dad76a 100644 --- a/aiogram_bot_template/keyboards/inline/consts.py +++ b/aiogram_bot_template/keyboards/inline/consts.py @@ -1,4 +1,4 @@ -from typing import Type, TypeVar +from typing import Type, TypeVar, Union from aiogram.filters.callback_data import CallbackData from aiogram.types import ( @@ -15,7 +15,7 @@ class InlineConstructor: aliases = {"cb": "callback_data"} - available_properities = [ + available_properties = [ "text", "callback_data", "url", @@ -32,7 +32,7 @@ def _create_kb( actions: list[ dict[ str, - str | bool | A | LoginUrl | CallbackGame, + Union[str, bool, A, LoginUrl, CallbackGame], ] ], schema: list[int], @@ -42,7 +42,7 @@ def _create_kb( for a in actions: data: dict[ str, - str | bool | A | LoginUrl | CallbackGame, + Union[str, bool, A, LoginUrl, CallbackGame], ] = {} for k, v in InlineConstructor.aliases.items(): if k in a: diff --git a/poetry.lock b/poetry.lock index 9c0bbce1..2f64b4fd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. [[package]] name = "aiofiles" @@ -1358,5 +1358,5 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" -python-versions = "^3.10" -content-hash = "f318c9db2ef8381da71c874bc0ce37bb342c679261344b5b7aa77732ff020c85" +python-versions = "^3.9" +content-hash = "dfd886ce15df3dc31300722e03ba260c18bba6dc4fc10aa968d9d5a1c4fa0549" diff --git a/pyproject.toml b/pyproject.toml index 75459139..9a1032db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,14 +1,14 @@ [tool.black] -target-version = ["py310"] +target-version = ["py39"] [tool.isort] profile = "black" -py_version = 310 +py_version = 39 force_alphabetical_sort_within_sections = true group_by_package = true [tool.mypy] -python_version = "3.10" +python_version = "3.9" files = "bot.py" show_error_codes = true show_error_context = true @@ -40,15 +40,15 @@ ignore_missing_imports = true select = ["E", "F", "B"] ignore = ["E501"] unfixable = ["B"] -target-version = "py310" +target-version = "py39" ignore-init-module-imports = true [tool.poetry] -name = "aiogram-bot-template" -version = "2.2.0" +name = "faucetbot" +version = "0.1.0" description = "Template for creating scalable bots with aiogram" -authors = ["Forden <24463229+Forden@users.noreply.github.com>"] +authors = ["Sergio-prog"] readme = "README.md" packages = [{ include = "aiogram_bot_template" }] @@ -56,7 +56,7 @@ packages = [{ include = "aiogram_bot_template" }] aiogram_bot_template = "aiogram_bot_template.bot:main" [tool.poetry.dependencies] -python = "^3.10" +python = "^3.9" environs = "^9.5.0" aiohttp = "3.8.5" aiojobs = "1.2.0" From 8371959f43338273945b5c310106aed7d161184c Mon Sep 17 00:00:00 2001 From: Sergio-prog Date: Tue, 17 Oct 2023 14:21:56 +0300 Subject: [PATCH 2/2] Template for Python <3.10 --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9a1032db..18997bdd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,10 +45,10 @@ ignore-init-module-imports = true [tool.poetry] -name = "faucetbot" -version = "0.1.0" +name = "aiogram-bot-template" +version = "2.2.0" description = "Template for creating scalable bots with aiogram" -authors = ["Sergio-prog"] +authors = ["Forden <24463229+Forden@users.noreply.github.com>"] readme = "README.md" packages = [{ include = "aiogram_bot_template" }]