mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 22:56:38 +01:00
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:
parent
efea0361c5
commit
0bed087542
7 changed files with 2 additions and 38 deletions
|
@ -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):
|
||||
|
|
|
@ -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::
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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::
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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::
|
||||
|
||||
|
|
|
@ -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::
|
||||
|
||||
|
|
Loading…
Reference in a new issue