Skip to content
Merged
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
Empty file added cq/_core/common/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions cq/_core/common/typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from typing import Protocol


class Decorator(Protocol):
def __call__[T](self, wrapped: T, /) -> T: ...
13 changes: 7 additions & 6 deletions cq/_core/dispatcher/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, Protocol, Self, overload

from cq._core.common.typing import Decorator
from cq._core.dispatcher.base import BaseDispatcher, Dispatcher
from cq._core.middleware import Middleware

Expand Down Expand Up @@ -46,13 +47,13 @@ def step[T](
) -> PipeConverter[T, Any]: ...

@overload
def step[T](
def step(
self,
wrapped: None = ...,
/,
*,
dispatcher: Dispatcher[T, Any] | None = ...,
) -> Callable[[PipeConverter[T, Any]], PipeConverter[T, Any]]: ...
dispatcher: Dispatcher[Any, Any] | None = ...,
) -> Decorator: ...

def step[T](
self,
Expand Down Expand Up @@ -163,13 +164,13 @@ def step[T](
) -> PipeConverterMethod[T, Any]: ...

@overload
def step[T](
def step(
self,
wrapped: None = ...,
/,
*,
dispatcher: Dispatcher[T, Any] | None = ...,
) -> Callable[[PipeConverterMethod[T, Any]], PipeConverterMethod[T, Any]]: ...
dispatcher: Dispatcher[Any, Any] | None = ...,
) -> Decorator: ...

def step[T](
self,
Expand Down
10 changes: 4 additions & 6 deletions cq/_core/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import injection
from type_analyzer import MatchingTypesConfig, iter_matching_types, matching_types

from cq._core.common.typing import Decorator

type HandlerType[**P, T] = type[Handler[P, T]]
type HandlerFactory[**P, T] = Callable[..., Awaitable[Handler[P, T]]]

Expand Down Expand Up @@ -90,10 +92,6 @@ def subscribe(self, input_type: type[I], factory: HandlerFactory[[I], O]) -> Sel
return self


class _Decorator(Protocol):
def __call__[T](self, wrapped: T, /) -> T: ...


@dataclass(repr=False, eq=False, frozen=True, slots=True)
class HandlerDecorator[I, O]:
registry: HandlerRegistry[I, O]
Expand All @@ -108,7 +106,7 @@ def __call__(
/,
*,
threadsafe: bool | None = ...,
) -> _Decorator: ...
) -> Decorator: ...

@overload
def __call__[T](
Expand All @@ -126,7 +124,7 @@ def __call__(
/,
*,
threadsafe: bool | None = ...,
) -> _Decorator: ...
) -> Decorator: ...

def __call__[T](
self,
Expand Down
2 changes: 1 addition & 1 deletion cq/_core/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
command_handler: Final[HandlerDecorator[Command, Any]] = HandlerDecorator(
SingleHandlerRegistry(),
)
event_handler: Final[HandlerDecorator[Event, None]] = HandlerDecorator(
event_handler: Final[HandlerDecorator[Event, Any]] = HandlerDecorator(
MultipleHandlerRegistry(),
)
query_handler: Final[HandlerDecorator[Query, Any]] = HandlerDecorator(
Expand Down
9 changes: 3 additions & 6 deletions cq/_core/pipetools.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import TYPE_CHECKING, Any, Callable, overload
from typing import TYPE_CHECKING, Any, overload

import injection

from cq import Dispatcher
from cq._core.common.typing import Decorator
from cq._core.dispatcher.lazy import LazyDispatcher
from cq._core.dispatcher.pipe import ContextPipeline, PipeConverterMethod
from cq._core.message import AnyCommandBus, Command, Query, QueryBus
Expand Down Expand Up @@ -52,11 +53,7 @@ def query_step[T: Query](
) -> PipeConverterMethod[T, Any]: ...

@overload
def query_step[T: Query](
self,
wrapped: None = ...,
/,
) -> Callable[[PipeConverterMethod[T, Any]], PipeConverterMethod[T, Any]]: ...
def query_step(self, wrapped: None = ..., /) -> Decorator: ...

def query_step[T: Query](
self,
Expand Down
48 changes: 24 additions & 24 deletions uv.lock

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