From 4f7bdfa885827188c7dd3147b58e9ea280bb3201 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sun, 21 May 2017 17:04:09 +0300 Subject: [PATCH] Remove bot entity from types. --- aiogram/types/__init__.py | 15 ++++----------- aiogram/types/chat.py | 3 --- aiogram/types/update.py | 11 +++++++---- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/aiogram/types/__init__.py b/aiogram/types/__init__.py index bd5e22af..6e630934 100644 --- a/aiogram/types/__init__.py +++ b/aiogram/types/__init__.py @@ -18,16 +18,6 @@ class Deserializable: All subclasses of this class must override de_json. """ - @property - def bot(self): - if not hasattr(self, '_bot'): - raise AttributeError('object is not configured for bot.') - return getattr(self, '_bot') - - @bot.setter - def bot(self, bot): - setattr(self, '_bot', bot) - def to_json(self): return getattr(self, 'data', {}) @@ -42,7 +32,7 @@ class Deserializable: raise NotImplementedError @staticmethod - def check_json(data): + def check_json(data) -> dict: """ Checks whether json_type is a dict or a string. If it is already a dict, it is returned as-is. If it is not, it is converted to a dict by means of json.loads(json_type) @@ -59,3 +49,6 @@ class Deserializable: def __str__(self): return json.dumps(self.to_json()) + + def __repr__(self): + return str(self) diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index 6396f154..8921ca31 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -40,9 +40,6 @@ class Chat(Deserializable): return Chat(data, id, type, title, username, first_name, last_name, all_members_are_administrators) - async def send_message(self, text): - self.bot.send_message(self.id, text) - @property def full_name(self): if self.type == ChatType.PRIVATE: diff --git a/aiogram/types/update.py b/aiogram/types/update.py index 564bba3a..aeb8f7a6 100644 --- a/aiogram/types/update.py +++ b/aiogram/types/update.py @@ -3,15 +3,18 @@ from aiogram.types.message import Message class Update(Deserializable): + __slots__ = ('update_id', 'message', 'edited_message', 'channel_post', 'edited_channel_post', 'inline_query', + 'chosen_inline_result', 'callback_query', 'shipping_query', 'pre_checkout_query') + def __init__(self, data, update_id, message, edited_message, channel_post, edited_channel_post, inline_query, chosen_inline_result, callback_query, shipping_query, pre_checkout_query): self.data = data self.update_id = update_id - self.message = message - self.edited_message = edited_message - self.channel_post = channel_post - self.edited_channel_post = edited_channel_post + self.message: Message = message + self.edited_message: Message = edited_message + self.channel_post: Message = channel_post + self.edited_channel_post: Message = edited_channel_post self.inline_query = inline_query self.chosen_inline_result = chosen_inline_result self.callback_query = callback_query