Skip to content

Commit a93cbd1

Browse files
authored
Merge pull request #262 from euri10/typing_context
fix: type context with generics
2 parents 7a31b94 + 687f7b3 commit a93cbd1

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

saq/types.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import typing as t
88
from collections.abc import Collection
9-
from typing_extensions import Required, TypedDict
9+
from typing_extensions import Required, TypedDict, Generic
1010

1111
if t.TYPE_CHECKING:
1212
from asyncio import Task
@@ -110,7 +110,10 @@ class PartialTimersDict(TimersDict, total=False):
110110
"""
111111

112112

113-
class SettingsDict(TypedDict, total=False):
113+
CtxType = t.TypeVar("CtxType", bound=Context)
114+
115+
116+
class SettingsDict(TypedDict, Generic[CtxType], total=False):
114117
"""
115118
Settings
116119
"""
@@ -119,10 +122,10 @@ class SettingsDict(TypedDict, total=False):
119122
functions: Required[Collection[Function | tuple[str, Function]]]
120123
concurrency: int
121124
cron_jobs: Collection[CronJob]
122-
startup: ReceivesContext
123-
shutdown: ReceivesContext
124-
before_process: ReceivesContext
125-
after_process: ReceivesContext
125+
startup: ReceivesContext[CtxType]
126+
shutdown: ReceivesContext[CtxType]
127+
before_process: ReceivesContext[CtxType]
128+
after_process: ReceivesContext[CtxType]
126129
timers: PartialTimersDict
127130
dequeue_timeout: float
128131

@@ -134,5 +137,5 @@ class SettingsDict(TypedDict, total=False):
134137
Function = t.Callable[..., t.Any]
135138
ListenCallback = t.Callable[[str, "Status"], t.Any]
136139
LoadType = t.Callable[[t.Union[bytes, str]], t.Any]
137-
ReceivesContext = t.Callable[[Context], t.Any]
140+
ReceivesContext = t.Callable[[CtxType], t.Any]
138141
VersionTuple = t.Tuple[int, ...]

0 commit comments

Comments
 (0)