mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
perf
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
__all__ = ["CommandHandler", "CommandHandlers"]
|
||||
|
||||
from collections.abc import Iterator
|
||||
from typing import Callable
|
||||
from typing import Callable, Never
|
||||
|
||||
from argenta.command import Command
|
||||
from argenta.response import Response
|
||||
|
||||
|
||||
HandlerFunc = Callable[..., None]
|
||||
|
||||
|
||||
@@ -30,7 +29,7 @@ class CommandHandler:
|
||||
|
||||
|
||||
class CommandHandlers:
|
||||
def __init__(self, command_handlers: tuple[CommandHandler] = tuple()):
|
||||
def __init__(self, command_handlers: tuple[CommandHandler] | tuple[Never, ...] = tuple()):
|
||||
"""
|
||||
Private. The model that unites all CommandHandler of the routers
|
||||
:param command_handlers: list of CommandHandlers for register
|
||||
@@ -49,7 +48,7 @@ class CommandHandlers:
|
||||
for alias in command_handler.handled_command.aliases:
|
||||
self.paired_command_handler_trigger[alias.lower()] = command_handler
|
||||
|
||||
def get_command_handler_by_trigger(self, trigger: str):
|
||||
def get_command_handler_by_trigger(self, trigger: str) -> CommandHandler | None:
|
||||
print(self.paired_command_handler_trigger)
|
||||
return self.paired_command_handler_trigger.get(trigger)
|
||||
|
||||
|
||||
@@ -7,16 +7,14 @@ from rich.console import Console
|
||||
|
||||
from argenta.command import Command, InputCommand
|
||||
from argenta.command.flag import ValidationStatus
|
||||
from argenta.command.flag.flags import Flags, InputFlags
|
||||
from argenta.command.flag.flags import InputFlags
|
||||
from argenta.response import Response, ResponseStatus
|
||||
from argenta.router.command_handler.entity import CommandHandler, CommandHandlers
|
||||
from argenta.router.exceptions import (
|
||||
RepeatedAliasNameException,
|
||||
RepeatedFlagNameException,
|
||||
RepeatedTriggerNameException,
|
||||
RequiredArgumentNotPassedException,
|
||||
TriggerContainSpacesException,
|
||||
)
|
||||
from argenta.router.exceptions import (RepeatedAliasNameException,
|
||||
RepeatedFlagNameException,
|
||||
RepeatedTriggerNameException,
|
||||
RequiredArgumentNotPassedException,
|
||||
TriggerContainSpacesException)
|
||||
|
||||
HandlerFunc: TypeAlias = Callable[..., None]
|
||||
|
||||
@@ -42,8 +40,6 @@ class Router:
|
||||
self.disable_redirect_stdout: bool = disable_redirect_stdout
|
||||
|
||||
self.command_handlers: CommandHandlers = CommandHandlers()
|
||||
self.command_register_ignore: bool = False
|
||||
|
||||
self.aliases: set[str] = set()
|
||||
self.triggers: set[str] = set()
|
||||
|
||||
@@ -87,12 +83,11 @@ class Router:
|
||||
if overlapping := (self.aliases | self.triggers) & set(map(lambda x: x.lower(), command.aliases)):
|
||||
raise RepeatedAliasNameException(overlapping)
|
||||
|
||||
flags: Flags = command.registered_flags
|
||||
flags_name: list[str] = [flag.string_entity.lower() for flag in flags]
|
||||
flags_name: list[str] = [flag.string_entity.lower() for flag in command.registered_flags]
|
||||
if len(set(flags_name)) < len(flags_name):
|
||||
raise RepeatedFlagNameException()
|
||||
|
||||
def _update_routing_keys(self, registered_command: Command):
|
||||
def _update_routing_keys(self, registered_command: Command) -> None:
|
||||
redefined_command_aliases_in_lower = set(map(lambda x: x.lower(), registered_command.aliases))
|
||||
self.aliases.update(redefined_command_aliases_in_lower)
|
||||
self.triggers.add(registered_command.trigger.lower())
|
||||
|
||||
Reference in New Issue
Block a user