Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template for Python <3.10 #11

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import typing
from typing import Any, Optional, TypeVar
from typing import Any, Optional, TypeVar, Union

T = TypeVar("T")

Expand Down Expand Up @@ -32,23 +32,23 @@ 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

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

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
3 changes: 2 additions & 1 deletion aiogram_bot_template/filters/chat_type.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
6 changes: 4 additions & 2 deletions aiogram_bot_template/filters/text.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 4 additions & 4 deletions aiogram_bot_template/keyboards/inline/consts.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -15,7 +15,7 @@

class InlineConstructor:
aliases = {"cb": "callback_data"}
available_properities = [
available_properties = [
"text",
"callback_data",
"url",
Expand All @@ -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],
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -40,7 +40,7 @@ ignore_missing_imports = true
select = ["E", "F", "B"]
ignore = ["E501"]
unfixable = ["B"]
target-version = "py310"
target-version = "py39"
ignore-init-module-imports = true


Expand All @@ -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"
Expand Down