11from collections import deque
22from collections .abc import Awaitable , Callable
33from dataclasses import dataclass , field
4- from typing import Any , Protocol , Self , overload
4+ from typing import TYPE_CHECKING , Any , Protocol , Self , overload
55
66from cq ._core .dispatcher .base import BaseDispatcher , Dispatcher
77from cq ._core .middleware import Middleware
@@ -34,23 +34,25 @@ def __init__(self, dispatcher: Dispatcher[Any, Any]) -> None:
3434 self .__dispatcher = dispatcher
3535 self .__steps = []
3636
37- @overload
38- def step [T ](
39- self ,
40- wrapped : PipeConverter [T , Any ],
41- / ,
42- * ,
43- dispatcher : Dispatcher [T , Any ] | None = ...,
44- ) -> PipeConverter [T , Any ]: ...
45-
46- @overload
47- def step [T ](
48- self ,
49- wrapped : None = ...,
50- / ,
51- * ,
52- dispatcher : Dispatcher [T , Any ] | None = ...,
53- ) -> Callable [[PipeConverter [T , Any ]], PipeConverter [T , Any ]]: ...
37+ if TYPE_CHECKING : # pragma: no cover
38+
39+ @overload
40+ def step [T ](
41+ self ,
42+ wrapped : PipeConverter [T , Any ],
43+ / ,
44+ * ,
45+ dispatcher : Dispatcher [T , Any ] | None = ...,
46+ ) -> PipeConverter [T , Any ]: ...
47+
48+ @overload
49+ def step [T ](
50+ self ,
51+ wrapped : None = ...,
52+ / ,
53+ * ,
54+ dispatcher : Dispatcher [T , Any ] | None = ...,
55+ ) -> Callable [[PipeConverter [T , Any ]], PipeConverter [T , Any ]]: ...
5456
5557 def step [T ](
5658 self ,
@@ -114,23 +116,33 @@ def __init__(self, dispatcher: Dispatcher[Any, Any]) -> None:
114116 self .__middlewares = deque ()
115117 self .__steps = []
116118
117- @overload
118- def __get__ [O ](
119- self ,
120- instance : O ,
121- owner : type [O ] | None = ...,
122- ) -> Dispatcher [I , O ]: ...
119+ if TYPE_CHECKING : # pragma: no cover
120+
121+ @overload
122+ def __get__ [O ](self , instance : None , owner : type [O ], / ) -> Dispatcher [I , O ]: ...
123123
124- @overload
125- def __get__ (self , instance : None = ..., owner : type | None = ...) -> Self : ...
124+ @overload
125+ def __get__ [O ](
126+ self ,
127+ instance : O ,
128+ owner : type [O ] | None = ...,
129+ / ,
130+ ) -> Dispatcher [I , O ]: ...
131+
132+ @overload
133+ def __get__ (self , instance : None = ..., owner : None = ..., / ) -> Self : ...
126134
127135 def __get__ [O ](
128136 self ,
129137 instance : O | None = None ,
130138 owner : type [O ] | None = None ,
139+ / ,
131140 ) -> Self | Dispatcher [I , O ]:
132141 if instance is None :
133- return self
142+ if owner is None :
143+ return self
144+
145+ instance = owner ()
134146
135147 pipeline = self .__new_pipeline (instance , owner )
136148 return BoundContextPipeline (instance , pipeline )
@@ -139,23 +151,25 @@ def add_middlewares(self, *middlewares: Middleware[[I], Any]) -> Self:
139151 self .__middlewares .extendleft (reversed (middlewares ))
140152 return self
141153
142- @overload
143- def step [T ](
144- self ,
145- wrapped : PipeConverterMethod [T , Any ],
146- / ,
147- * ,
148- dispatcher : Dispatcher [T , Any ] | None = ...,
149- ) -> PipeConverterMethod [T , Any ]: ...
150-
151- @overload
152- def step [T ](
153- self ,
154- wrapped : None = ...,
155- / ,
156- * ,
157- dispatcher : Dispatcher [T , Any ] | None = ...,
158- ) -> Callable [[PipeConverterMethod [T , Any ]], PipeConverterMethod [T , Any ]]: ...
154+ if TYPE_CHECKING : # pragma: no cover
155+
156+ @overload
157+ def step [T ](
158+ self ,
159+ wrapped : PipeConverterMethod [T , Any ],
160+ / ,
161+ * ,
162+ dispatcher : Dispatcher [T , Any ] | None = ...,
163+ ) -> PipeConverterMethod [T , Any ]: ...
164+
165+ @overload
166+ def step [T ](
167+ self ,
168+ wrapped : None = ...,
169+ / ,
170+ * ,
171+ dispatcher : Dispatcher [T , Any ] | None = ...,
172+ ) -> Callable [[PipeConverterMethod [T , Any ]], PipeConverterMethod [T , Any ]]: ...
159173
160174 def step [T ](
161175 self ,
0 commit comments