Skip to content

Commit e660ffb

Browse files
authored
feat: ✨ Overloads for decorators
1 parent fe17e08 commit e660ffb

File tree

4 files changed

+216
-161
lines changed

4 files changed

+216
-161
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# python-cq
22

33
[![CI](https://github.com/100nm/python-cq/actions/workflows/ci.yml/badge.svg)](https://github.com/100nm/python-cq)
4-
[![PyPI - Version](https://img.shields.io/pypi/v/python-cq.svg?color=blue)](https://pypi.org/project/python-cq/)
4+
[![PyPI - Version](https://img.shields.io/pypi/v/python-cq.svg?color=blue)](https://pypi.org/project/python-cq)
55
[![PyPI - Downloads](https://img.shields.io/pypi/dm/python-cq.svg?color=blue)](https://pypistats.org/packages/python-cq)
66
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
77

cq/_core/dispatcher/pipe.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Awaitable, Callable
22
from dataclasses import dataclass, field
3-
from typing import Any, Self
3+
from typing import Any, Self, overload
44

55
from cq._core.dispatcher.base import BaseDispatcher, Dispatcher
66

@@ -24,6 +24,24 @@ def __init__(self, dispatcher: Dispatcher[Any, Any]) -> None:
2424
self.__dispatcher = dispatcher
2525
self.__steps = []
2626

27+
@overload
28+
def step[T](
29+
self,
30+
wrapped: PipeConverter[T, Any],
31+
/,
32+
*,
33+
dispatcher: Dispatcher[T, Any] | None = ...,
34+
) -> PipeConverter[T, Any]: ...
35+
36+
@overload
37+
def step[T](
38+
self,
39+
wrapped: None = ...,
40+
/,
41+
*,
42+
dispatcher: Dispatcher[T, Any] | None = ...,
43+
) -> Callable[[PipeConverter[T, Any]], PipeConverter[T, Any]]: ...
44+
2745
def step[T](
2846
self,
2947
wrapped: PipeConverter[T, Any] | None = None,

cq/_core/handler.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from functools import partial
66
from inspect import Parameter, getmro, isclass
77
from inspect import signature as inspect_signature
8-
from typing import Any, Protocol, Self, runtime_checkable
8+
from typing import Any, Protocol, Self, overload, runtime_checkable
99

1010
import injection
1111

@@ -89,6 +89,27 @@ class HandlerDecorator[I, O]:
8989
manager: HandlerManager[I, O]
9090
injection_module: injection.Module = field(default_factory=injection.mod)
9191

92+
@overload
93+
def __call__(
94+
self,
95+
input_or_handler_type: type[I],
96+
/,
97+
) -> Callable[[HandlerType[[I], O]], HandlerType[[I], O]]: ...
98+
99+
@overload
100+
def __call__(
101+
self,
102+
input_or_handler_type: HandlerType[[I], O],
103+
/,
104+
) -> HandlerType[[I], O]: ...
105+
106+
@overload
107+
def __call__(
108+
self,
109+
input_or_handler_type: None = ...,
110+
/,
111+
) -> Callable[[HandlerType[[I], O]], HandlerType[[I], O]]: ...
112+
92113
def __call__(
93114
self,
94115
input_or_handler_type: type[I] | HandlerType[[I], O] | None = None,

0 commit comments

Comments
 (0)