Skip to content

Commit 08d298e

Browse files
ihorutsnoam
authored andcommitted
TelegramObject.de_json became classmethod (python-telegram-bot#737)
Fixes python-telegram-bot#734
1 parent 5a37af6 commit 08d298e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+343
-295
lines changed

telegram/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def __str__(self):
3737
def __getitem__(self, item):
3838
return self.__dict__[item]
3939

40-
@staticmethod
41-
def de_json(data, bot):
40+
@classmethod
41+
def de_json(cls, data, bot):
4242
"""
4343
Args:
4444
data (dict):

telegram/bot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,11 +2581,11 @@ def delete_sticker_from_set(self, sticker, timeout=None, **kwargs):
25812581

25822582
return result
25832583

2584-
@staticmethod
2585-
def de_json(data, bot):
2586-
data = super(Bot, Bot).de_json(data, bot)
2584+
@classmethod
2585+
def de_json(cls, data, bot):
2586+
data = super(Bot, cls).de_json(data, bot)
25872587

2588-
return Bot(**data)
2588+
return cls(**data)
25892589

25902590
def to_dict(self):
25912591
data = {'id': self.id, 'username': self.username, 'first_name': self.username}

telegram/callbackquery.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def __init__(self,
4646

4747
self.bot = bot
4848

49-
@staticmethod
50-
def de_json(data, bot):
49+
@classmethod
50+
def de_json(cls, data, bot):
5151
"""
5252
Args:
5353
data (dict):
@@ -60,12 +60,12 @@ def de_json(data, bot):
6060
if not data:
6161
return None
6262

63-
data = super(CallbackQuery, CallbackQuery).de_json(data, bot)
63+
data = super(CallbackQuery, cls).de_json(data, bot)
6464

6565
data['from_user'] = User.de_json(data.get('from'), bot)
6666
data['message'] = Message.de_json(data.get('message'), bot)
6767

68-
return CallbackQuery(bot=bot, **data)
68+
return cls(bot=bot, **data)
6969

7070
def to_dict(self):
7171
"""

telegram/chat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def __init__(self,
7878
self.bot = bot
7979
self._id_attrs = (self.id,)
8080

81-
@staticmethod
82-
def de_json(data, bot):
81+
@classmethod
82+
def de_json(cls, data, bot):
8383
"""
8484
Args:
8585
data (dict):
@@ -93,7 +93,7 @@ def de_json(data, bot):
9393

9494
data['photo'] = ChatPhoto.de_json(data.get('photo'), bot)
9595

96-
return Chat(bot=bot, **data)
96+
return cls(bot=bot, **data)
9797

9898
def send_action(self, *args, **kwargs):
9999
"""Shortcut for ``bot.send_chat_action(update.message.chat.id, *args, **kwargs)``"""

telegram/chatmember.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def __init__(self, user, status, until_date=None, can_be_edited=None,
9898

9999
self._id_attrs = (self.user, self.status)
100100

101-
@staticmethod
102-
def de_json(data, bot):
101+
@classmethod
102+
def de_json(cls, data, bot):
103103
"""
104104
Args:
105105
data (dict):
@@ -111,12 +111,12 @@ def de_json(data, bot):
111111
if not data:
112112
return None
113113

114-
data = super(ChatMember, ChatMember).de_json(data, bot)
114+
data = super(ChatMember, cls).de_json(data, bot)
115115

116116
data['user'] = User.de_json(data.get('user'), bot)
117117
data['until_date'] = from_timestamp(data.get('until_date', None))
118118

119-
return ChatMember(**data)
119+
return cls(**data)
120120

121121
def to_dict(self):
122122
"""

telegram/choseninlineresult.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def __init__(self,
6464

6565
self._id_attrs = (self.result_id,)
6666

67-
@staticmethod
68-
def de_json(data, bot):
67+
@classmethod
68+
def de_json(cls, data, bot):
6969
"""
7070
Args:
7171
data (dict):
@@ -77,13 +77,13 @@ def de_json(data, bot):
7777
if not data:
7878
return None
7979

80-
data = super(ChosenInlineResult, ChosenInlineResult).de_json(data, bot)
80+
data = super(ChosenInlineResult, cls).de_json(data, bot)
8181
# Required
8282
data['from_user'] = User.de_json(data.pop('from'), bot)
8383
# Optionals
8484
data['location'] = Location.de_json(data.get('location'), bot)
8585

86-
return ChosenInlineResult(**data)
86+
return cls(**data)
8787

8888
def to_dict(self):
8989
"""

telegram/files/audio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def __init__(self,
6262

6363
self._id_attrs = (self.file_id,)
6464

65-
@staticmethod
66-
def de_json(data, bot):
65+
@classmethod
66+
def de_json(cls, data, bot):
6767
"""
6868
Args:
6969
data (dict):
@@ -75,4 +75,4 @@ def de_json(data, bot):
7575
if not data:
7676
return None
7777

78-
return Audio(**data)
78+
return cls(**data)

telegram/files/chatphoto.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def __init__(self, small_file_id, big_file_id, bot=None, **kwargs):
3939
self.small_file_id = small_file_id
4040
self.big_file_id = big_file_id
4141

42-
@staticmethod
43-
def de_json(data, bot):
42+
@classmethod
43+
def de_json(cls, data, bot):
4444
"""
4545
Args:
4646
data (dict):
@@ -52,4 +52,4 @@ def de_json(data, bot):
5252
if not data:
5353
return None
5454

55-
return ChatPhoto(bot=bot, **data)
55+
return cls(bot=bot, **data)

telegram/files/contact.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def __init__(self, phone_number, first_name, last_name=None, user_id=None, **kwa
4949

5050
self._id_attrs = (self.phone_number,)
5151

52-
@staticmethod
53-
def de_json(data, bot):
52+
@classmethod
53+
def de_json(cls, data, bot):
5454
"""
5555
Args:
5656
data (dict):
@@ -62,4 +62,4 @@ def de_json(data, bot):
6262
if not data:
6363
return None
6464

65-
return Contact(**data)
65+
return cls(**data)

telegram/files/document.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def __init__(self,
6060

6161
self._id_attrs = (self.file_id,)
6262

63-
@staticmethod
64-
def de_json(data, bot):
63+
@classmethod
64+
def de_json(cls, data, bot):
6565
"""
6666
Args:
6767
data (dict):
@@ -73,8 +73,8 @@ def de_json(data, bot):
7373
if not data:
7474
return None
7575

76-
data = super(Document, Document).de_json(data, bot)
76+
data = super(Document, cls).de_json(data, bot)
7777

7878
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
7979

80-
return Document(**data)
80+
return cls(**data)

0 commit comments

Comments
 (0)