diff --git a/aiogram/types/base.py b/aiogram/types/base.py index 0ed8579c..4da3e9f4 100644 --- a/aiogram/types/base.py +++ b/aiogram/types/base.py @@ -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: diff --git a/aiogram/types/chat_member.py b/aiogram/types/chat_member.py index 71d6d755..372b3468 100644 --- a/aiogram/types/chat_member.py +++ b/aiogram/types/chat_member.py @@ -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) diff --git a/aiogram/types/fields.py b/aiogram/types/fields.py index 40b0da50..7994f04e 100644 --- a/aiogram/types/fields.py +++ b/aiogram/types/fields.py @@ -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