mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
ref: typehints, enum instead of raw string, abc and other (#1)
Full code coverage with annotations, fixing errors in various linters: ruff, wps, etc. Fixing errors in type checkers: ty, mypy, pyright. Formatting and bringing code to a consistent style, applying best practices in various aspects.
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
from typing import Callable, Iterator
|
||||
from collections.abc import Iterator
|
||||
from typing import Callable
|
||||
|
||||
from argenta.command import Command
|
||||
from argenta.response import Response
|
||||
|
||||
|
||||
class CommandHandler:
|
||||
def __init__(self, handler: Callable[[Response], None], handled_command: Command):
|
||||
def __init__(self, handler_as_func: Callable[[Response], None], handled_command: Command):
|
||||
"""
|
||||
Private. Entity of the model linking the handler and the command being processed
|
||||
:param handler: the handler being called
|
||||
:param handled_command: the command being processed
|
||||
"""
|
||||
self._handler = handler
|
||||
self._handled_command = handled_command
|
||||
self.handler_as_func: Callable[[Response], None] = handler_as_func
|
||||
self.handled_command: Command = handled_command
|
||||
|
||||
def handling(self, response: Response) -> None:
|
||||
"""
|
||||
@@ -20,21 +21,7 @@ class CommandHandler:
|
||||
:param response: the entity of response: various groups of flags and status of response
|
||||
:return: None
|
||||
"""
|
||||
self._handler(response)
|
||||
|
||||
def get_handler(self) -> Callable[[Response], None]:
|
||||
"""
|
||||
Private. Returns the handler being called
|
||||
:return: the handler being called as Callable[[Response], None]
|
||||
"""
|
||||
return self._handler
|
||||
|
||||
def get_handled_command(self) -> Command:
|
||||
"""
|
||||
Private. Returns the command being processed
|
||||
:return: the command being processed as Command
|
||||
"""
|
||||
return self._handled_command
|
||||
self.handler_as_func(response)
|
||||
|
||||
|
||||
class CommandHandlers:
|
||||
@@ -43,14 +30,7 @@ class CommandHandlers:
|
||||
Private. The model that unites all CommandHandler of the routers
|
||||
:param command_handlers: list of CommandHandlers for register
|
||||
"""
|
||||
self.command_handlers = command_handlers if command_handlers else []
|
||||
|
||||
def get_handlers(self) -> list[CommandHandler]:
|
||||
"""
|
||||
Private. Returns the list of CommandHandlers
|
||||
:return: the list of CommandHandlers as list[CommandHandler]
|
||||
"""
|
||||
return self.command_handlers
|
||||
self.command_handlers: list[CommandHandler] = command_handlers if command_handlers else []
|
||||
|
||||
def add_handler(self, command_handler: CommandHandler) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user