mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Try to use contextvars (partial)
This commit is contained in:
parent
c88ee7ed52
commit
8086a120c2
7 changed files with 54 additions and 7 deletions
|
|
@ -1,3 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from contextvars import ContextVar
|
||||
|
||||
from . import base
|
||||
from . import fields
|
||||
from .callback_query import CallbackQuery
|
||||
|
|
@ -8,6 +12,8 @@ from .pre_checkout_query import PreCheckoutQuery
|
|||
from .shipping_query import ShippingQuery
|
||||
from ..utils import helper
|
||||
|
||||
current_update: ContextVar[Update] = ContextVar('current_update_object', default=None)
|
||||
|
||||
|
||||
class Update(base.TelegramObject):
|
||||
"""
|
||||
|
|
@ -27,6 +33,14 @@ class Update(base.TelegramObject):
|
|||
shipping_query: ShippingQuery = fields.Field(base=ShippingQuery)
|
||||
pre_checkout_query: PreCheckoutQuery = fields.Field(base=PreCheckoutQuery)
|
||||
|
||||
@classmethod
|
||||
def current(cls):
|
||||
return current_update.get()
|
||||
|
||||
@classmethod
|
||||
def set_current(cls, update: Update):
|
||||
return current_update.set(update)
|
||||
|
||||
def __hash__(self):
|
||||
return self.update_id
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue