Skip to content

Commit a89cac1

Browse files
authored
Fixed type inference for new versions of pyright and dependencies were updated. (#413)
1 parent 528c2db commit a89cac1

File tree

14 files changed

+884
-780
lines changed

14 files changed

+884
-780
lines changed

.python-version

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
3.11.4
2-
3.10.12
3-
3.9.17
4-
3.8.17
1+
3.13.1
2+
3.12.8
3+
3.11.11
4+
3.10.16
5+
3.9.21

poetry.lock

Lines changed: 781 additions & 662 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ classifiers = [
2828
keywords = ["taskiq", "tasks", "distributed", "async"]
2929

3030
[tool.poetry.dependencies]
31-
python = "^3.8.1"
31+
python = "^3.9"
3232
typing-extensions = ">=3.10.0.0"
3333
pydantic = ">=1.0,<=3.0"
3434
importlib-metadata = "*"
@@ -51,7 +51,7 @@ msgpack = { version = "^1.0.7", optional = true }
5151
cbor2 = { version = "^5", optional = true }
5252
izulu = "0.5.4"
5353

54-
[tool.poetry.dev-dependencies]
54+
[tool.poetry.group.dev.dependencies]
5555
pytest = "^7.1.2"
5656
ruff = "^0"
5757
black = { version = "^22.6.0", allow-prereleases = true }
@@ -157,8 +157,6 @@ lint.ignore = [
157157
"D401", # First line should be in imperative mood
158158
"D104", # Missing docstring in public package
159159
"D100", # Missing docstring in public module
160-
"ANN102", # Missing type annotation for self in method
161-
"ANN101", # Missing type annotation for argument
162160
"ANN401", # typing.Any are disallowed in `**kwargs
163161
"PLR0913", # Too many arguments for function call
164162
"D106", # Missing docstring in public nested class

taskiq/__init__.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,35 @@
3535

3636
__version__ = version("taskiq")
3737
__all__ = [
38-
"__version__",
39-
"gather",
40-
"Context",
38+
"AckableMessage",
4139
"AsyncBroker",
42-
"TaskiqError",
43-
"TaskiqState",
44-
"TaskiqResult",
45-
"ZeroMQBroker",
46-
"TaskiqEvents",
47-
"SecurityError",
48-
"TaskiqMessage",
40+
"AsyncResultBackend",
41+
"AsyncTaskiqDecoratedTask",
42+
"AsyncTaskiqTask",
4943
"BrokerMessage",
44+
"Context",
45+
"InMemoryBroker",
46+
"NoResultError",
47+
"PrometheusMiddleware",
5048
"ResultGetError",
49+
"ResultIsReadyError",
50+
"ScheduleSource",
5151
"ScheduledTask",
52-
"TaskiqDepends",
53-
"NoResultError",
52+
"SecurityError",
5453
"SendTaskError",
55-
"AckableMessage",
56-
"InMemoryBroker",
57-
"ScheduleSource",
58-
"TaskiqScheduler",
54+
"SimpleRetryMiddleware",
55+
"TaskiqDepends",
56+
"TaskiqError",
57+
"TaskiqEvents",
5958
"TaskiqFormatter",
60-
"AsyncTaskiqTask",
59+
"TaskiqMessage",
6160
"TaskiqMiddleware",
62-
"ResultIsReadyError",
63-
"AsyncResultBackend",
64-
"async_shared_broker",
65-
"PrometheusMiddleware",
66-
"SimpleRetryMiddleware",
67-
"AsyncTaskiqDecoratedTask",
61+
"TaskiqResult",
6862
"TaskiqResultTimeoutError",
63+
"TaskiqScheduler",
64+
"TaskiqState",
65+
"ZeroMQBroker",
66+
"__version__",
67+
"async_shared_broker",
68+
"gather",
6969
]

taskiq/abc/middleware.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from types import CoroutineType
12
from typing import TYPE_CHECKING, Any, Coroutine, Union
23

34
if TYPE_CHECKING: # pragma: no cover # pragma: no cover
@@ -20,7 +21,9 @@ def set_broker(self, broker: "AsyncBroker") -> None:
2021
"""
2122
self.broker = broker
2223

23-
def startup(self) -> "Union[None, Coroutine[Any, Any, None]]":
24+
def startup(
25+
self,
26+
) -> Union[None, Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]"]:
2427
"""
2528
Startup method to perform various action during startup.
2629
@@ -30,7 +33,9 @@ def startup(self) -> "Union[None, Coroutine[Any, Any, None]]":
3033
:returns nothing.
3134
"""
3235

33-
def shutdown(self) -> "Union[None, Coroutine[Any, Any, None]]":
36+
def shutdown(
37+
self,
38+
) -> Union[None, Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]"]:
3439
"""
3540
Shutdown method to perform various action during shutdown.
3641
@@ -43,7 +48,11 @@ def shutdown(self) -> "Union[None, Coroutine[Any, Any, None]]":
4348
def pre_send(
4449
self,
4550
message: "TaskiqMessage",
46-
) -> "Union[TaskiqMessage, Coroutine[Any, Any, TaskiqMessage]]":
51+
) -> Union[
52+
"TaskiqMessage",
53+
"Coroutine[Any, Any, TaskiqMessage]",
54+
"CoroutineType[Any, Any, TaskiqMessage]",
55+
]:
4756
"""
4857
Hook that executes before sending the task to worker.
4958
@@ -58,7 +67,7 @@ def pre_send(
5867
def post_send(
5968
self,
6069
message: "TaskiqMessage",
61-
) -> "Union[None, Coroutine[Any, Any, None]]":
70+
) -> Union[None, Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]"]:
6271
"""
6372
This hook is executed right after the task is sent.
6473
@@ -71,7 +80,11 @@ def post_send(
7180
def pre_execute(
7281
self,
7382
message: "TaskiqMessage",
74-
) -> "Union[TaskiqMessage, Coroutine[Any, Any, TaskiqMessage]]":
83+
) -> Union[
84+
"TaskiqMessage",
85+
"Coroutine[Any, Any, TaskiqMessage]",
86+
"CoroutineType[Any, Any, TaskiqMessage]",
87+
]:
7588
"""
7689
This hook is called before executing task.
7790
@@ -87,7 +100,7 @@ def post_execute(
87100
self,
88101
message: "TaskiqMessage",
89102
result: "TaskiqResult[Any]",
90-
) -> "Union[None, Coroutine[Any, Any, None]]":
103+
) -> Union[None, Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]"]:
91104
"""
92105
This hook executes after task is complete.
93106
@@ -102,7 +115,7 @@ def post_save(
102115
self,
103116
message: "TaskiqMessage",
104117
result: "TaskiqResult[Any]",
105-
) -> "Union[None, Coroutine[Any, Any, None]]":
118+
) -> Union[None, Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]"]:
106119
"""
107120
Post save hook.
108121
@@ -118,7 +131,7 @@ def on_error(
118131
message: "TaskiqMessage",
119132
result: "TaskiqResult[Any]",
120133
exception: BaseException,
121-
) -> "Union[None, Coroutine[Any, Any, None]]":
134+
) -> Union[None, Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]"]:
122135
"""
123136
This function is called when exception is found.
124137

taskiq/abc/schedule_source.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from abc import ABC, abstractmethod
2-
from typing import TYPE_CHECKING, Any, Coroutine, List, Union
2+
from collections.abc import Coroutine
3+
from types import CoroutineType
4+
from typing import TYPE_CHECKING, Any, List, Union
35

46
if TYPE_CHECKING: # pragma: no cover
57
from taskiq.scheduler.scheduled_task import ScheduledTask
@@ -56,7 +58,7 @@ async def delete_schedule(self, schedule_id: str) -> None:
5658
def pre_send( # noqa: B027
5759
self,
5860
task: "ScheduledTask",
59-
) -> Union[None, Coroutine[Any, Any, None]]:
61+
) -> Union[None, "CoroutineType[Any, Any, None]", Coroutine[Any, Any, None]]:
6062
"""
6163
Actions to execute before task will be sent to broker.
6264
@@ -69,7 +71,7 @@ def pre_send( # noqa: B027
6971
def post_send( # noqa: B027
7072
self,
7173
task: "ScheduledTask",
72-
) -> Union[None, Coroutine[Any, Any, None]]:
74+
) -> Union[None, "CoroutineType[Any, Any, None]", Coroutine[Any, Any, None]]:
7375
"""
7476
Actions to execute after task was sent to broker.
7577

taskiq/decor.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from collections.abc import Coroutine
12
from datetime import datetime
3+
from types import CoroutineType
24
from typing import (
35
TYPE_CHECKING,
46
Any,
57
Callable,
6-
Coroutine,
78
Dict,
89
Generic,
910
TypeVar,
@@ -64,6 +65,14 @@ def __call__( # noqa: D102
6465
) -> _ReturnType:
6566
return self.original_func(*args, **kwargs)
6667

68+
@overload
69+
async def kiq(
70+
self: "AsyncTaskiqDecoratedTask[_FuncParams, CoroutineType[Any, Any, _T]]",
71+
*args: _FuncParams.args,
72+
**kwargs: _FuncParams.kwargs,
73+
) -> AsyncTaskiqTask[_T]:
74+
...
75+
6776
@overload
6877
async def kiq(
6978
self: "AsyncTaskiqDecoratedTask[_FuncParams, Coroutine[Any, Any, _T]]",

taskiq/kicker.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from collections.abc import Coroutine
12
from dataclasses import asdict, is_dataclass
23
from datetime import datetime
34
from logging import getLogger
5+
from types import CoroutineType
46
from typing import (
57
TYPE_CHECKING,
68
Any,
7-
Coroutine,
89
Dict,
910
Generic,
1011
Optional,
@@ -107,6 +108,14 @@ def with_broker(
107108
self.broker = broker
108109
return self
109110

111+
@overload
112+
async def kiq(
113+
self: "AsyncKicker[_FuncParams, CoroutineType[Any, Any, _T]]",
114+
*args: _FuncParams.args,
115+
**kwargs: _FuncParams.kwargs,
116+
) -> AsyncTaskiqTask[_T]: # pragma: no cover
117+
...
118+
110119
@overload
111120
async def kiq(
112121
self: "AsyncKicker[_FuncParams, Coroutine[Any, Any, _T]]",

taskiq/scheduler/created_schedule.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import TYPE_CHECKING, Any, Coroutine, Generic, TypeVar, overload
1+
from collections.abc import Coroutine
2+
from types import CoroutineType
3+
from typing import TYPE_CHECKING, Any, Generic, TypeVar, overload
24

35
from taskiq.abc.schedule_source import ScheduleSource
46
from taskiq.scheduler.scheduled_task import ScheduledTask
@@ -25,14 +27,22 @@ def __init__(
2527
self.task = task
2628
self.schedule_id = task.schedule_id
2729

30+
@overload
31+
async def kiq(
32+
self: "CreatedSchedule[CoroutineType[Any,Any, _T]]",
33+
) -> AsyncTaskiqTask[_T]:
34+
...
35+
2836
@overload
2937
async def kiq(
3038
self: "CreatedSchedule[Coroutine[Any,Any, _T]]",
3139
) -> AsyncTaskiqTask[_T]:
3240
...
3341

3442
@overload
35-
async def kiq(self: "CreatedSchedule[_ReturnType]") -> AsyncTaskiqTask[_ReturnType]:
43+
async def kiq(
44+
self: "CreatedSchedule[_ReturnType]",
45+
) -> AsyncTaskiqTask[_ReturnType]:
3646
...
3747

3848
async def kiq(self) -> Any:

taskiq/serializers/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from .pickle import PickleSerializer
77

88
__all__ = [
9+
"CBORSerializer",
910
"JSONSerializer",
10-
"ORJSONSerializer",
1111
"MSGPackSerializer",
12-
"CBORSerializer",
12+
"ORJSONSerializer",
1313
"PickleSerializer",
1414
]

0 commit comments

Comments
 (0)