This commit is contained in:
2026-01-15 14:52:41 +03:00
parent 3cd74fc186
commit 18f62d3e7c
5 changed files with 51 additions and 31 deletions
+2 -3
View File
@@ -1,13 +1,12 @@
__all__ = ["CommandHandler", "CommandHandlers"]
from collections.abc import Iterator
from typing import Callable, Never
from typing import Never
from argenta.app.protocols import HandlerFunc
from argenta.command import Command
from argenta.response import Response
HandlerFunc = Callable[..., None]
class CommandHandler:
def __init__(self, handler_as_func: HandlerFunc, handled_command: Command):
+10 -12
View File
@@ -1,10 +1,11 @@
__all__ = ["Router"]
from inspect import get_annotations, getfullargspec, getsourcefile, getsourcelines
from typing import Callable, TypeAlias
from typing import Callable
from rich.console import Console
from argenta.app.protocols import HandlerFunc
from argenta.command import Command, InputCommand
from argenta.command.flag import ValidationStatus
from argenta.command.flag.flags import InputFlags
@@ -16,8 +17,6 @@ from argenta.router.exceptions import (RepeatedAliasNameException,
RequiredArgumentNotPassedException,
TriggerContainSpacesException)
HandlerFunc: TypeAlias = Callable[..., None]
class Router:
def __init__(
@@ -176,13 +175,12 @@ def _validate_func_args(func: HandlerFunc) -> None:
response_arg_annotation = func_annotations.get(response_arg)
if response_arg_annotation is not None:
if response_arg_annotation is not Response:
source_line: int = getsourcelines(func)[1]
Console().print(
f'\nFile "{getsourcefile(func)}", line {source_line}\n[b red]WARNING:[/b red] [i]The typehint '
+ f"of argument([green]{response_arg}[/green]) passed to the handler must be [/i][bold blue]{Response}[/bold blue],"
+ f" [i]but[/i] [bold blue]{response_arg_annotation}[/bold blue] [i]is specified[/i]",
highlight=False,
)
if response_arg_annotation is not None and response_arg_annotation is not Response:
source_line: int = getsourcelines(func)[1]
Console().print(
f'\nFile "{getsourcefile(func)}", line {source_line}\n[b red]WARNING:[/b red] [i]The typehint '
+ f"of argument([green]{response_arg}[/green]) passed to the handler must be [/i][bold blue]{Response}[/bold blue],"
+ f" [i]but[/i] [bold blue]{response_arg_annotation}[/bold blue] [i]is specified[/i]",
highlight=False,
)