Skip to content

Commit 6f84cdb

Browse files
Fix #795: Fix typing of actor decorator to work with async actors (#796)
* Fix #795: Incorrect typing with async decorators * add contrubutor, ignore E704
1 parent bb8853d commit 6f84cdb

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
max-complexity = 20
33
max-line-length = 120
44
select = C,E,F,W,B,B9,Q0
5-
ignore = E127,E203,E402,E501,F403,F811,W503,W504,B010,B020,B036,B905,B908
5+
ignore = E127,E203,E402,E501,E704,F403,F811,W503,W504,B010,B020,B036,B905,B908
66

77
inline-quotes = double
88
multiline-quotes = double

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ of those changes to CLEARTYPE SRL.
7575
| [@gurelkaynak](https://gurel.kaynak.link) | Gurel Kaynak |
7676
| [@ksoviero-zengrc](https://github.com/ksoviero-zengrc) | Kevin Soviero |
7777
| [@mikeroll](https://github.com/mikeroll) | Mikhail Bulash |
78+
| [@janek-cosmose](https://github.com/janek-cosmose) | Jan Szejko |

dramatiq/actor.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
Generic,
2828
Optional,
2929
ParamSpec,
30+
Protocol,
3031
TypeVar,
3132
Union,
3233
overload,
@@ -202,13 +203,28 @@ def __str__(self) -> str:
202203
return "Actor(%(actor_name)s)" % vars(self)
203204

204205

206+
class ActorDecorator(Protocol):
207+
@overload
208+
def __call__(self, fn: Callable[P, Awaitable[R]]) -> Actor[P, R]: ...
209+
210+
@overload
211+
def __call__(self, fn: Callable[P, R]) -> Actor[P, R]: ...
212+
213+
def __call__(self, fn: Callable[P, Union[Awaitable[R], R]]) -> Actor[P, R]: ...
214+
215+
216+
@overload
217+
def actor(fn: Callable[P, Awaitable[R]], **kwargs) -> Actor[P, R]:
218+
pass
219+
220+
205221
@overload
206-
def actor(fn: Callable[P, Union[Awaitable[R], R]], **kwargs) -> Actor[P, R]:
222+
def actor(fn: Callable[P, R], **kwargs) -> Actor[P, R]:
207223
pass
208224

209225

210226
@overload
211-
def actor(fn: None = None, **kwargs) -> Callable[[Callable[P, Union[Awaitable[R], R]]], Actor[P, R]]:
227+
def actor(fn: None = None, **kwargs) -> ActorDecorator:
212228
pass
213229

214230

0 commit comments

Comments
 (0)