remove unnecessary to_dict() (#834)

We have some objects that have exactly the same to_dict() method, only specifying that `from_user` should be `from` in the `data`-dict. I refractored this logic to `TelegramObject` and removed those to_dicts() from the code.
This commit is contained in:
Eldinnie 2018-02-19 09:31:38 +01:00 committed by Noam Meltzer
parent efea0361c5
commit 0bed087542
7 changed files with 2 additions and 38 deletions

View file

@ -70,6 +70,8 @@ class TelegramObject(object):
else:
data[key] = value
if data.get('from_user'):
data['from'] = data.pop('from_user', None)
return data
def __eq__(self, other):

View file

@ -105,13 +105,6 @@ class CallbackQuery(TelegramObject):
return cls(bot=bot, **data)
def to_dict(self):
data = super(CallbackQuery, self).to_dict()
# Required
data['from'] = data.pop('from_user', None)
return data
def answer(self, *args, **kwargs):
"""Shortcut for::

View file

@ -79,11 +79,3 @@ class ChosenInlineResult(TelegramObject):
data['location'] = Location.de_json(data.get('location'), bot)
return cls(**data)
def to_dict(self):
data = super(ChosenInlineResult, self).to_dict()
# Required
data['from'] = data.pop('from_user', None)
return data

View file

@ -75,14 +75,6 @@ class InlineQuery(TelegramObject):
return cls(bot=bot, **data)
def to_dict(self):
data = super(InlineQuery, self).to_dict()
# Required
data['from'] = data.pop('from_user', None)
return data
def answer(self, *args, **kwargs):
"""Shortcut for::

View file

@ -387,7 +387,6 @@ class Message(TelegramObject):
data = super(Message, self).to_dict()
# Required
data['from'] = data.pop('from_user', None)
data['date'] = to_timestamp(self.date)
# Optionals
if self.forward_date:

View file

@ -89,13 +89,6 @@ class PreCheckoutQuery(TelegramObject):
return cls(bot=bot, **data)
def to_dict(self):
data = super(PreCheckoutQuery, self).to_dict()
data['from'] = data.pop('from_user', None)
return data
def answer(self, *args, **kwargs):
"""Shortcut for::

View file

@ -66,13 +66,6 @@ class ShippingQuery(TelegramObject):
return cls(**data)
def to_dict(self):
data = super(ShippingQuery, self).to_dict()
data['from'] = data.pop('from_user', None)
return data
def answer(self, *args, **kwargs):
"""Shortcut for::