mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Add prototype of class-based handlers
This commit is contained in:
parent
2a731f7ce2
commit
b82a1a6fb0
11 changed files with 178 additions and 8 deletions
|
|
@ -45,9 +45,13 @@ class ContextInstanceMixin:
|
|||
return cls.__context_instance.get()
|
||||
|
||||
@classmethod
|
||||
def set_current(cls: Type[T], value: T):
|
||||
def set_current(cls: Type[T], value: T) -> contextvars.Token:
|
||||
if not isinstance(value, cls):
|
||||
raise TypeError(
|
||||
f"Value should be instance of {cls.__name__!r} not {type(value).__name__!r}"
|
||||
)
|
||||
cls.__context_instance.set(value)
|
||||
return cls.__context_instance.set(value)
|
||||
|
||||
@classmethod
|
||||
def reset_current(cls: Type[T], token: contextvars.Token):
|
||||
cls.__context_instance.reset(token)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue