Skip to content

Commit 0bed087

Browse files
Eldinnietsnoam
authored andcommitted
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.
1 parent efea036 commit 0bed087

File tree

7 files changed

+2
-38
lines changed

7 files changed

+2
-38
lines changed

telegram/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def to_dict(self):
7070
else:
7171
data[key] = value
7272

73+
if data.get('from_user'):
74+
data['from'] = data.pop('from_user', None)
7375
return data
7476

7577
def __eq__(self, other):

telegram/callbackquery.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ def de_json(cls, data, bot):
105105

106106
return cls(bot=bot, **data)
107107

108-
def to_dict(self):
109-
data = super(CallbackQuery, self).to_dict()
110-
111-
# Required
112-
data['from'] = data.pop('from_user', None)
113-
return data
114-
115108
def answer(self, *args, **kwargs):
116109
"""Shortcut for::
117110

telegram/choseninlineresult.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,3 @@ def de_json(cls, data, bot):
7979
data['location'] = Location.de_json(data.get('location'), bot)
8080

8181
return cls(**data)
82-
83-
def to_dict(self):
84-
data = super(ChosenInlineResult, self).to_dict()
85-
86-
# Required
87-
data['from'] = data.pop('from_user', None)
88-
89-
return data

telegram/inline/inlinequery.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ def de_json(cls, data, bot):
7575

7676
return cls(bot=bot, **data)
7777

78-
def to_dict(self):
79-
data = super(InlineQuery, self).to_dict()
80-
81-
# Required
82-
data['from'] = data.pop('from_user', None)
83-
84-
return data
85-
8678
def answer(self, *args, **kwargs):
8779
"""Shortcut for::
8880

telegram/message.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ def to_dict(self):
387387
data = super(Message, self).to_dict()
388388

389389
# Required
390-
data['from'] = data.pop('from_user', None)
391390
data['date'] = to_timestamp(self.date)
392391
# Optionals
393392
if self.forward_date:

telegram/payment/precheckoutquery.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ def de_json(cls, data, bot):
8989

9090
return cls(bot=bot, **data)
9191

92-
def to_dict(self):
93-
data = super(PreCheckoutQuery, self).to_dict()
94-
95-
data['from'] = data.pop('from_user', None)
96-
97-
return data
98-
9992
def answer(self, *args, **kwargs):
10093
"""Shortcut for::
10194

telegram/payment/shippingquery.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,6 @@ def de_json(cls, data, bot):
6666

6767
return cls(**data)
6868

69-
def to_dict(self):
70-
data = super(ShippingQuery, self).to_dict()
71-
72-
data['from'] = data.pop('from_user', None)
73-
74-
return data
75-
7669
def answer(self, *args, **kwargs):
7770
"""Shortcut for::
7871

0 commit comments

Comments
 (0)