From 29be6782d6f75eda6e1a1a2c945af4a0492ece42 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Thu, 22 Aug 2024 12:17:54 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D0=BE=20TC2?= =?UTF-8?q?00?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .flake8 | 2 +- .../karkas_blocks/standard/config/miniapp_ui.py | 6 +++--- src/karkas_blocks/karkas_blocks/standard/filters/filters.py | 6 +++--- src/karkas_blocks/karkas_blocks/standard/help/main.py | 2 +- src/karkas_blocks/karkas_blocks/standard/welcome/main.py | 6 +++--- .../standard/welcome/verifications_methods/base.py | 4 ++-- .../standard/welcome/verifications_methods/simple.py | 4 ++-- .../standard/welcome/verifications_methods/utils.py | 4 ++-- src/karkas_core/karkas_core/lib.py | 4 ++-- src/karkas_core/karkas_core/modules_system/loaders/base.py | 2 +- .../karkas_core/modules_system/public_api/public_api.py | 4 ++-- src/karkas_core/karkas_core/modules_system/safe/policy.py | 2 +- src/karkas_core/karkas_core/singleton.py | 6 +++--- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.flake8 b/.flake8 index 1228e76..fb9ec7c 100644 --- a/.flake8 +++ b/.flake8 @@ -5,4 +5,4 @@ max-line-length = 88 count = true extend-ignore = E203,E701 -extend-select = TC010 +extend-select = TC010,TC200 diff --git a/src/karkas_blocks/karkas_blocks/standard/config/miniapp_ui.py b/src/karkas_blocks/karkas_blocks/standard/config/miniapp_ui.py index 56a9964..420bd8f 100644 --- a/src/karkas_blocks/karkas_blocks/standard/config/miniapp_ui.py +++ b/src/karkas_blocks/karkas_blocks/standard/config/miniapp_ui.py @@ -18,7 +18,7 @@ if TYPE_CHECKING: from .config_manager import ConfigManager -def create_control(key: str, config: ConfigManager): +def create_control(key: str, config: "ConfigManager"): value = config.get(key) meta = config.get_meta(key) @@ -85,7 +85,7 @@ def create_control(key: str, config: ConfigManager): return dbc.Row(row, className="mb-3 mx-1") -def build_settings_tree(config: ConfigManager): +def build_settings_tree(config: "ConfigManager"): tree = {} for key, value in config._metadata.items(): @@ -134,7 +134,7 @@ def create_settings_components(tree, level=0): return components -def get_miniapp_blueprint(config: ConfigManager, prefix: str): +def get_miniapp_blueprint(config: "ConfigManager", prefix: str): Roles: "type[IRoles]" = get_module("standard.roles", "Roles") roles = Roles() diff --git a/src/karkas_blocks/karkas_blocks/standard/filters/filters.py b/src/karkas_blocks/karkas_blocks/standard/filters/filters.py index 2400d95..f5cb247 100644 --- a/src/karkas_blocks/karkas_blocks/standard/filters/filters.py +++ b/src/karkas_blocks/karkas_blocks/standard/filters/filters.py @@ -35,7 +35,7 @@ def get_approved_chat_id() -> list: @deprecated("Use ChatIDFilter or own implementation") -def chat_not_in_approve(message: Message) -> bool: +def chat_not_in_approve(message: "Message") -> bool: chat_id = message.chat.id if chat_id in get_approved_chat_id(): # log(f"Chat in approve list: {chat_id}") @@ -51,7 +51,7 @@ class ChatIDFilter(BaseFilter): self.approved_chats = approved_chats super().__init__() - async def __call__(self, message: Message, bot: Bot) -> bool: + async def __call__(self, message: "Message", bot: "Bot") -> bool: chat_id = message.chat.id approved_chats = self.approved_chats or get_approved_chat_id() @@ -71,7 +71,7 @@ class ChatNotInApproveFilter(ChatIDFilter): class ChatModerOrAdminFilter(BaseFilter): - async def __call__(self, message: Message, bot: Bot) -> bool: + async def __call__(self, message: "Message", bot: "Bot") -> bool: if not ROLES_MODULE_LOADED: raise Exception("Roles module not loaded") diff --git a/src/karkas_blocks/karkas_blocks/standard/help/main.py b/src/karkas_blocks/karkas_blocks/standard/help/main.py index 9a789c9..a254934 100644 --- a/src/karkas_blocks/karkas_blocks/standard/help/main.py +++ b/src/karkas_blocks/karkas_blocks/standard/help/main.py @@ -47,7 +47,7 @@ def format_commands(commands_dict): return "\n".join(formatted_commands) -async def help(message: Message): +async def help(message: "Message"): commands = "" version = "" diff --git a/src/karkas_blocks/karkas_blocks/standard/welcome/main.py b/src/karkas_blocks/karkas_blocks/standard/welcome/main.py index f52f0a7..2f4acba 100644 --- a/src/karkas_blocks/karkas_blocks/standard/welcome/main.py +++ b/src/karkas_blocks/karkas_blocks/standard/welcome/main.py @@ -79,7 +79,7 @@ verification_tasks = MultiKeyDict() last_success = {} -async def new_member_handler(event: ChatMemberUpdated, bot: Bot): +async def new_member_handler(event: "ChatMemberUpdated", bot: Bot): # НЕ СРАБОТАЕТ, ЕСЛИ ЧЕЛОВЕК УЖЕ ОГРАНИЧЕН В ПРАВАХ (RESTRICTED) if event.new_chat_member.status == ChatMemberStatus.MEMBER: task = task_manager.build_random_task(event, bot) @@ -88,7 +88,7 @@ async def new_member_handler(event: ChatMemberUpdated, bot: Bot): verification_tasks.add(task, keys) -async def left_member_handler(event: ChatMemberUpdated, bot: Bot): +async def left_member_handler(event: "ChatMemberUpdated", bot: Bot): user_id = event.from_user.id chat_id = event.chat.id @@ -145,7 +145,7 @@ async def success_end(task: BaseTask): last_success[task.from_chat_id] = message.message_id -async def handle_poll_verification(answer: PollAnswer, bot: Bot): +async def handle_poll_verification(answer: "PollAnswer", bot: Bot): key = key_from_poll(answer.poll_id) if not verification_tasks.exists(key): return diff --git a/src/karkas_blocks/karkas_blocks/standard/welcome/verifications_methods/base.py b/src/karkas_blocks/karkas_blocks/standard/welcome/verifications_methods/base.py index 0bb376f..f9be39a 100644 --- a/src/karkas_blocks/karkas_blocks/standard/welcome/verifications_methods/base.py +++ b/src/karkas_blocks/karkas_blocks/standard/welcome/verifications_methods/base.py @@ -17,8 +17,8 @@ if TYPE_CHECKING: class BaseTask: def __init__( self, - event: ChatMemberUpdated, - bot: Bot, + event: "ChatMemberUpdated", + bot: "Bot", timeout_func=None, attempt_number=1, max_attempts=1, diff --git a/src/karkas_blocks/karkas_blocks/standard/welcome/verifications_methods/simple.py b/src/karkas_blocks/karkas_blocks/standard/welcome/verifications_methods/simple.py index d3e8ee3..d392622 100644 --- a/src/karkas_blocks/karkas_blocks/standard/welcome/verifications_methods/simple.py +++ b/src/karkas_blocks/karkas_blocks/standard/welcome/verifications_methods/simple.py @@ -123,8 +123,8 @@ class SimpleInlineButtonsTask(SimpleVariantsBaseTask): class SimplePollTask(SimpleVariantsBaseTask): def __init__( self, - event: ChatMemberUpdated, - bot: Bot, + event: "ChatMemberUpdated", + bot: "Bot", timeout_func=None, attempt_number=1, max_attempts=1, diff --git a/src/karkas_blocks/karkas_blocks/standard/welcome/verifications_methods/utils.py b/src/karkas_blocks/karkas_blocks/standard/welcome/verifications_methods/utils.py index 20eb56b..0365f6f 100644 --- a/src/karkas_blocks/karkas_blocks/standard/welcome/verifications_methods/utils.py +++ b/src/karkas_blocks/karkas_blocks/standard/welcome/verifications_methods/utils.py @@ -17,7 +17,7 @@ def user_mention(user: User, mode=ParseMode.HTML): raise ValueError(f"Unknown parse mode {mode}") -async def mute_user(chat_id, user_id, until, bot: Bot): +async def mute_user(chat_id, user_id, until, bot: "Bot"): end_time = until + int(time.time()) await bot.restrict_chat_member( chat_id, @@ -43,7 +43,7 @@ async def mute_user(chat_id, user_id, until, bot: Bot): ) -async def unmute_user(chat_id, user_id, bot: Bot): +async def unmute_user(chat_id, user_id, bot: "Bot"): await bot.restrict_chat_member( chat_id, user_id, diff --git a/src/karkas_core/karkas_core/lib.py b/src/karkas_core/karkas_core/lib.py index c126ef3..6608524 100644 --- a/src/karkas_core/karkas_core/lib.py +++ b/src/karkas_core/karkas_core/lib.py @@ -20,8 +20,8 @@ def get_module_directory(module_name): return os.path.dirname(module_path) -async def register_bot_webhook(app: FastAPI, bot: Bot, dp: Dispatcher): - async def handle_webhook(request: Request): +async def register_bot_webhook(app: "FastAPI", bot: "Bot", dp: "Dispatcher"): + async def handle_webhook(request: "Request"): try: update = Update.model_validate(await request.json(), context={"bot": bot}) await dp.feed_update(bot, update) diff --git a/src/karkas_core/karkas_core/modules_system/loaders/base.py b/src/karkas_core/karkas_core/modules_system/loaders/base.py index 74f848f..9696931 100644 --- a/src/karkas_core/karkas_core/modules_system/loaders/base.py +++ b/src/karkas_core/karkas_core/modules_system/loaders/base.py @@ -41,5 +41,5 @@ class AbstractLoader: def info(self) -> ModuleInfo: raise NotImplementedError - def load(self) -> types.ModuleType: + def load(self) -> "types.ModuleType": raise NotImplementedError diff --git a/src/karkas_core/karkas_core/modules_system/public_api/public_api.py b/src/karkas_core/karkas_core/modules_system/public_api/public_api.py index 3fb36c9..6b0869a 100644 --- a/src/karkas_core/karkas_core/modules_system/public_api/public_api.py +++ b/src/karkas_core/karkas_core/modules_system/public_api/public_api.py @@ -18,12 +18,12 @@ async def set_chat_menu_button(menu_button): await app.bot.set_chat_menu_button(menu_button=menu_button) -def register_router(router: Router): +def register_router(router: "Router"): app = Singleton() app.storage["_routers"].append(router) -def register_outer_message_middleware(middleware: BaseMiddleware): +def register_outer_message_middleware(middleware: "BaseMiddleware"): app = Singleton() app.storage["_outer_message_middlewares"].append(middleware) diff --git a/src/karkas_core/karkas_core/modules_system/safe/policy.py b/src/karkas_core/karkas_core/modules_system/safe/policy.py index f41f185..58c11ac 100644 --- a/src/karkas_core/karkas_core/modules_system/safe/policy.py +++ b/src/karkas_core/karkas_core/modules_system/safe/policy.py @@ -52,7 +52,7 @@ class RestrictedPythonPolicy(RestrictingNodeTransformer): return self.node_contents_visit(node) """ - def visit_AnnAssign(self, node: AnnAssign) -> Any: + def visit_AnnAssign(self, node: "AnnAssign") -> Any: # missing in RestrictingNodeTransformer # this doesn't need the logic that is in visit_Assign # because it doesn't have a "targets" attribute, diff --git a/src/karkas_core/karkas_core/singleton.py b/src/karkas_core/karkas_core/singleton.py index a46a058..cc0a2f0 100644 --- a/src/karkas_core/karkas_core/singleton.py +++ b/src/karkas_core/karkas_core/singleton.py @@ -19,9 +19,9 @@ class SingletonMeta(type): class Singleton(metaclass=SingletonMeta): - bot: Bot - dp: Dispatcher = None - modules_manager: ModulesManager = None + bot: "Bot" + dp: "Dispatcher" = None + modules_manager: "ModulesManager" = None storage = { "_fsm_storage": MemoryStorage(), "_routers": [],