Skip to content

Commit

Permalink
remove unnecessary to_dict() (#834)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Eldinnie authored and tsnoam committed Feb 19, 2018
1 parent efea036 commit 0bed087
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 38 deletions.
2 changes: 2 additions & 0 deletions telegram/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def to_dict(self):
else:
data[key] = value

if data.get('from_user'):
data['from'] = data.pop('from_user', None)
return data

def __eq__(self, other):
Expand Down
7 changes: 0 additions & 7 deletions telegram/callbackquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ def de_json(cls, data, bot):

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::
Expand Down
8 changes: 0 additions & 8 deletions telegram/choseninlineresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,3 @@ def de_json(cls, data, bot):
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
8 changes: 0 additions & 8 deletions telegram/inline/inlinequery.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ def de_json(cls, data, bot):

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::
Expand Down
1 change: 0 additions & 1 deletion telegram/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ def to_dict(self):
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:
Expand Down
7 changes: 0 additions & 7 deletions telegram/payment/precheckoutquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ def de_json(cls, data, bot):

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::
Expand Down
7 changes: 0 additions & 7 deletions telegram/payment/shippingquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ def de_json(cls, data, bot):

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::
Expand Down

0 comments on commit 0bed087

Please sign in to comment.