mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
fix: deserialize via to_object method (#624)
This commit is contained in:
parent
2b4e3ad5c6
commit
7a9bab01eb
3 changed files with 18 additions and 3 deletions
|
|
@ -139,14 +139,18 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject):
|
|||
return type(self).telegram_types
|
||||
|
||||
@classmethod
|
||||
def to_object(cls: typing.Type[T], data: typing.Dict[str, typing.Any]) -> T:
|
||||
def to_object(cls: typing.Type[T],
|
||||
data: typing.Dict[str, typing.Any],
|
||||
conf: typing.Dict[str, typing.Any] = None
|
||||
) -> T:
|
||||
"""
|
||||
Deserialize object
|
||||
|
||||
:param data:
|
||||
:param conf:
|
||||
:return:
|
||||
"""
|
||||
return cls(**data)
|
||||
return cls(conf=conf, **data)
|
||||
|
||||
@property
|
||||
def bot(self) -> Bot:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import datetime
|
||||
import typing
|
||||
from typing import Optional
|
||||
|
||||
from . import base, fields
|
||||
|
|
@ -6,6 +7,9 @@ from .user import User
|
|||
from ..utils import helper
|
||||
|
||||
|
||||
T = typing.TypeVar('T')
|
||||
|
||||
|
||||
class ChatMemberStatus(helper.Helper):
|
||||
"""
|
||||
Chat member status
|
||||
|
|
@ -81,6 +85,13 @@ class ChatMember(base.TelegramObject):
|
|||
|
||||
return class_(**kwargs)
|
||||
|
||||
@classmethod
|
||||
def to_object(cls,
|
||||
data: typing.Dict[str, typing.Any],
|
||||
conf: typing.Dict[str, typing.Any] = None
|
||||
) -> "ChatMember":
|
||||
return cls.resolve(**data)
|
||||
|
||||
def is_chat_creator(self) -> bool:
|
||||
return ChatMemberStatus.is_chat_creator(self.status)
|
||||
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ class Field(BaseField):
|
|||
and not hasattr(value, 'to_python'):
|
||||
if not isinstance(parent, weakref.ReferenceType):
|
||||
parent = weakref.ref(parent)
|
||||
return self.base_object(conf={'parent':parent}, **value)
|
||||
return self.base_object.to_object(conf={'parent': parent}, data=value)
|
||||
return value
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue