diff --git a/telegram/base.py b/telegram/base.py index 0aa6c0b81..afa38ccdb 100644 --- a/telegram/base.py +++ b/telegram/base.py @@ -37,8 +37,8 @@ class TelegramObject(object): def __getitem__(self, item): return self.__dict__[item] - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): diff --git a/telegram/bot.py b/telegram/bot.py index fc69906b9..4c3012182 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -2581,11 +2581,11 @@ class Bot(TelegramObject): return result - @staticmethod - def de_json(data, bot): - data = super(Bot, Bot).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(Bot, cls).de_json(data, bot) - return Bot(**data) + return cls(**data) def to_dict(self): data = {'id': self.id, 'username': self.username, 'first_name': self.username} diff --git a/telegram/callbackquery.py b/telegram/callbackquery.py index 3a0a0b181..e05885bf8 100644 --- a/telegram/callbackquery.py +++ b/telegram/callbackquery.py @@ -46,8 +46,8 @@ class CallbackQuery(TelegramObject): self.bot = bot - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -60,12 +60,12 @@ class CallbackQuery(TelegramObject): if not data: return None - data = super(CallbackQuery, CallbackQuery).de_json(data, bot) + data = super(CallbackQuery, cls).de_json(data, bot) data['from_user'] = User.de_json(data.get('from'), bot) data['message'] = Message.de_json(data.get('message'), bot) - return CallbackQuery(bot=bot, **data) + return cls(bot=bot, **data) def to_dict(self): """ diff --git a/telegram/chat.py b/telegram/chat.py index 87ca1d455..a35c8e9e2 100644 --- a/telegram/chat.py +++ b/telegram/chat.py @@ -78,8 +78,8 @@ class Chat(TelegramObject): self.bot = bot self._id_attrs = (self.id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -93,7 +93,7 @@ class Chat(TelegramObject): data['photo'] = ChatPhoto.de_json(data.get('photo'), bot) - return Chat(bot=bot, **data) + return cls(bot=bot, **data) def send_action(self, *args, **kwargs): """Shortcut for ``bot.send_chat_action(update.message.chat.id, *args, **kwargs)``""" diff --git a/telegram/chatmember.py b/telegram/chatmember.py index 1606cbb40..f71937b4c 100644 --- a/telegram/chatmember.py +++ b/telegram/chatmember.py @@ -98,8 +98,8 @@ class ChatMember(TelegramObject): self._id_attrs = (self.user, self.status) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -111,12 +111,12 @@ class ChatMember(TelegramObject): if not data: return None - data = super(ChatMember, ChatMember).de_json(data, bot) + data = super(ChatMember, cls).de_json(data, bot) data['user'] = User.de_json(data.get('user'), bot) data['until_date'] = from_timestamp(data.get('until_date', None)) - return ChatMember(**data) + return cls(**data) def to_dict(self): """ diff --git a/telegram/choseninlineresult.py b/telegram/choseninlineresult.py index b07a11933..3ffc53958 100644 --- a/telegram/choseninlineresult.py +++ b/telegram/choseninlineresult.py @@ -64,8 +64,8 @@ class ChosenInlineResult(TelegramObject): self._id_attrs = (self.result_id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -77,13 +77,13 @@ class ChosenInlineResult(TelegramObject): if not data: return None - data = super(ChosenInlineResult, ChosenInlineResult).de_json(data, bot) + data = super(ChosenInlineResult, cls).de_json(data, bot) # Required data['from_user'] = User.de_json(data.pop('from'), bot) # Optionals data['location'] = Location.de_json(data.get('location'), bot) - return ChosenInlineResult(**data) + return cls(**data) def to_dict(self): """ diff --git a/telegram/files/audio.py b/telegram/files/audio.py index 2500fd1ac..ec1c1160a 100644 --- a/telegram/files/audio.py +++ b/telegram/files/audio.py @@ -62,8 +62,8 @@ class Audio(TelegramObject): self._id_attrs = (self.file_id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -75,4 +75,4 @@ class Audio(TelegramObject): if not data: return None - return Audio(**data) + return cls(**data) diff --git a/telegram/files/chatphoto.py b/telegram/files/chatphoto.py index f9b38c17c..7d3abf0a3 100644 --- a/telegram/files/chatphoto.py +++ b/telegram/files/chatphoto.py @@ -39,8 +39,8 @@ class ChatPhoto(TelegramObject): self.small_file_id = small_file_id self.big_file_id = big_file_id - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -52,4 +52,4 @@ class ChatPhoto(TelegramObject): if not data: return None - return ChatPhoto(bot=bot, **data) + return cls(bot=bot, **data) diff --git a/telegram/files/contact.py b/telegram/files/contact.py index c9864f96a..e291f767d 100644 --- a/telegram/files/contact.py +++ b/telegram/files/contact.py @@ -49,8 +49,8 @@ class Contact(TelegramObject): self._id_attrs = (self.phone_number,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -62,4 +62,4 @@ class Contact(TelegramObject): if not data: return None - return Contact(**data) + return cls(**data) diff --git a/telegram/files/document.py b/telegram/files/document.py index a5aab2bbc..284b564e1 100644 --- a/telegram/files/document.py +++ b/telegram/files/document.py @@ -60,8 +60,8 @@ class Document(TelegramObject): self._id_attrs = (self.file_id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -73,8 +73,8 @@ class Document(TelegramObject): if not data: return None - data = super(Document, Document).de_json(data, bot) + data = super(Document, cls).de_json(data, bot) data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot) - return Document(**data) + return cls(**data) diff --git a/telegram/files/file.py b/telegram/files/file.py index f32c0a786..3860bcd1c 100644 --- a/telegram/files/file.py +++ b/telegram/files/file.py @@ -53,8 +53,8 @@ class File(TelegramObject): self._id_attrs = (self.file_id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -66,7 +66,7 @@ class File(TelegramObject): if not data: return None - return File(bot=bot, **data) + return cls(bot=bot, **data) def download(self, custom_path=None, out=None, timeout=None): """ diff --git a/telegram/files/location.py b/telegram/files/location.py index 72d78e2c6..e14d9019b 100644 --- a/telegram/files/location.py +++ b/telegram/files/location.py @@ -40,8 +40,8 @@ class Location(TelegramObject): self._id_attrs = (self.longitude, self.latitude) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -53,4 +53,4 @@ class Location(TelegramObject): if not data: return None - return Location(**data) + return cls(**data) diff --git a/telegram/files/photosize.py b/telegram/files/photosize.py index bdcc8aac4..bcda25c6d 100644 --- a/telegram/files/photosize.py +++ b/telegram/files/photosize.py @@ -50,8 +50,8 @@ class PhotoSize(TelegramObject): self._id_attrs = (self.file_id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -63,10 +63,10 @@ class PhotoSize(TelegramObject): if not data: return None - return PhotoSize(**data) + return cls(**data) - @staticmethod - def de_list(data, bot): + @classmethod + def de_list(cls, data, bot): """ Args: data (list): @@ -80,6 +80,6 @@ class PhotoSize(TelegramObject): photos = list() for photo in data: - photos.append(PhotoSize.de_json(photo, bot)) + photos.append(cls.de_json(photo, bot)) return photos diff --git a/telegram/files/sticker.py b/telegram/files/sticker.py index daeaf78c0..71e33b707 100644 --- a/telegram/files/sticker.py +++ b/telegram/files/sticker.py @@ -74,8 +74,8 @@ class Sticker(TelegramObject): self._id_attrs = (self.file_id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (:obj:`dict`): @@ -87,19 +87,19 @@ class Sticker(TelegramObject): if not data: return None - data = super(Sticker, Sticker).de_json(data, bot) + data = super(Sticker, cls).de_json(data, bot) data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot) data['mask_position'] = MaskPosition.de_json(data.get('mask_position'), bot) - return Sticker(**data) + return cls(**data) - @staticmethod - def de_list(data, bot): + @classmethod + def de_list(cls, data, bot): if not data: return list() - return [Sticker.de_json(d, bot) for d in data] + return [cls.de_json(d, bot) for d in data] class StickerSet(TelegramObject): @@ -190,9 +190,9 @@ class MaskPosition(TelegramObject): self.y_shift = y_shift self.zoom = zoom - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): if data is None: return None - return MaskPosition(**data) + return cls(**data) diff --git a/telegram/files/venue.py b/telegram/files/venue.py index 51376f405..b68febec5 100644 --- a/telegram/files/venue.py +++ b/telegram/files/venue.py @@ -42,13 +42,13 @@ class Venue(TelegramObject): self._id_attrs = (self.location, self.title) - @staticmethod - def de_json(data, bot): - data = super(Venue, Venue).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(Venue, cls).de_json(data, bot) if not data: return None data['location'] = Location.de_json(data.get('location'), bot) - return Venue(**data) + return cls(**data) diff --git a/telegram/files/video.py b/telegram/files/video.py index cd0b5d917..61fc7f815 100644 --- a/telegram/files/video.py +++ b/telegram/files/video.py @@ -67,8 +67,8 @@ class Video(TelegramObject): self._id_attrs = (self.file_id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -80,8 +80,8 @@ class Video(TelegramObject): if not data: return None - data = super(Video, Video).de_json(data, bot) + data = super(Video, cls).de_json(data, bot) data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot) - return Video(**data) + return cls(**data) diff --git a/telegram/files/videonote.py b/telegram/files/videonote.py index ba3616d43..eb47281c8 100644 --- a/telegram/files/videonote.py +++ b/telegram/files/videonote.py @@ -43,8 +43,8 @@ class VideoNote(TelegramObject): self._id_attrs = (self.file_id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -56,8 +56,8 @@ class VideoNote(TelegramObject): if not data: return None - data = super(VideoNote, VideoNote).de_json(data, bot) + data = super(VideoNote, cls).de_json(data, bot) data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot) - return VideoNote(**data) + return cls(**data) diff --git a/telegram/files/voice.py b/telegram/files/voice.py index ae5ecba20..331742929 100644 --- a/telegram/files/voice.py +++ b/telegram/files/voice.py @@ -50,8 +50,8 @@ class Voice(TelegramObject): self._id_attrs = (self.file_id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -63,6 +63,6 @@ class Voice(TelegramObject): if not data: return None - data = super(Voice, Voice).de_json(data, bot) + data = super(Voice, cls).de_json(data, bot) - return Voice(**data) + return cls(**data) diff --git a/telegram/forcereply.py b/telegram/forcereply.py index 981fed16c..b67eacbc1 100644 --- a/telegram/forcereply.py +++ b/telegram/forcereply.py @@ -41,8 +41,8 @@ class ForceReply(ReplyMarkup): # Optionals self.selective = bool(selective) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -54,4 +54,4 @@ class ForceReply(ReplyMarkup): if not data: return None - return ForceReply(**data) + return cls(**data) diff --git a/telegram/games/animation.py b/telegram/games/animation.py index 3a2763b7c..bcedd8b4c 100644 --- a/telegram/games/animation.py +++ b/telegram/games/animation.py @@ -50,21 +50,21 @@ class Animation(TelegramObject): self._id_attrs = (self.file_id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): bot (telegram.Bot): Returns: - telegram.Game: + telegram.Animation: """ if not data: return None - data = super(Animation, Animation).de_json(data, bot) + data = super(Animation, cls).de_json(data, bot) data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot) - return Animation(**data) + return cls(**data) diff --git a/telegram/games/game.py b/telegram/games/game.py index 0313e8c42..3a645b6bb 100644 --- a/telegram/games/game.py +++ b/telegram/games/game.py @@ -59,8 +59,8 @@ class Game(TelegramObject): self.text_entities = text_entities self.animation = animation - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -73,13 +73,13 @@ class Game(TelegramObject): if not data: return None - data = super(Game, Game).de_json(data, bot) + data = super(Game, cls).de_json(data, bot) data['photo'] = PhotoSize.de_list(data.get('photo'), bot) data['text_entities'] = MessageEntity.de_list(data.get('text_entities'), bot) data['animation'] = Animation.de_json(data.get('animation'), bot) - return Game(**data) + return cls(**data) def to_dict(self): """ diff --git a/telegram/games/gamehighscore.py b/telegram/games/gamehighscore.py index e49d185e4..f96703213 100644 --- a/telegram/games/gamehighscore.py +++ b/telegram/games/gamehighscore.py @@ -36,21 +36,21 @@ class GameHighScore(TelegramObject): self.user = user self.score = score - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): bot (telegram.Bot): Returns: - telegram.Game: + telegram.GameHighScore: """ if not data: return None - data = super(GameHighScore, GameHighScore).de_json(data, bot) + data = super(GameHighScore, cls).de_json(data, bot) data['user'] = User.de_json(data.get('user'), bot) - return GameHighScore(**data) + return cls(**data) diff --git a/telegram/inline/inlinekeyboardbutton.py b/telegram/inline/inlinekeyboardbutton.py index 0374461a7..66bc8eaff 100644 --- a/telegram/inline/inlinekeyboardbutton.py +++ b/telegram/inline/inlinekeyboardbutton.py @@ -74,8 +74,8 @@ class InlineKeyboardButton(TelegramObject): self.callback_game = callback_game self.pay = pay - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -84,20 +84,20 @@ class InlineKeyboardButton(TelegramObject): Returns: telegram.InlineKeyboardButton: """ - data = super(InlineKeyboardButton, InlineKeyboardButton).de_json(data, bot) + data = super(InlineKeyboardButton, cls).de_json(data, bot) if not data: return None - return InlineKeyboardButton(**data) + return cls(**data) - @staticmethod - def de_list(data, bot): + @classmethod + def de_list(cls, data, bot): if not data: return [] inline_keyboards = list() for inline_keyboard in data: - inline_keyboards.append(InlineKeyboardButton.de_json(inline_keyboard, bot)) + inline_keyboards.append(cls.de_json(inline_keyboard, bot)) return inline_keyboards diff --git a/telegram/inline/inlinekeyboardmarkup.py b/telegram/inline/inlinekeyboardmarkup.py index 2d9574a34..92593ec58 100644 --- a/telegram/inline/inlinekeyboardmarkup.py +++ b/telegram/inline/inlinekeyboardmarkup.py @@ -38,8 +38,8 @@ class InlineKeyboardMarkup(ReplyMarkup): # Required self.inline_keyboard = inline_keyboard - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -49,7 +49,7 @@ class InlineKeyboardMarkup(ReplyMarkup): telegram.InlineKeyboardMarkup: """ - data = super(InlineKeyboardMarkup, InlineKeyboardMarkup).de_json(data, bot) + data = super(InlineKeyboardMarkup, cls).de_json(data, bot) if not data: return None @@ -59,7 +59,7 @@ class InlineKeyboardMarkup(ReplyMarkup): for inline_keyboard in data['inline_keyboard'] ] - return InlineKeyboardMarkup(**data) + return cls(**data) def to_dict(self): data = super(InlineKeyboardMarkup, self).to_dict() diff --git a/telegram/inline/inlinequery.py b/telegram/inline/inlinequery.py index d8c7025b4..6ebce2413 100644 --- a/telegram/inline/inlinequery.py +++ b/telegram/inline/inlinequery.py @@ -58,8 +58,8 @@ class InlineQuery(TelegramObject): self.bot = bot self._id_attrs = (self.id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -68,7 +68,7 @@ class InlineQuery(TelegramObject): Returns: telegram.InlineQuery: """ - data = super(InlineQuery, InlineQuery).de_json(data, bot) + data = super(InlineQuery, cls).de_json(data, bot) if not data: return None @@ -76,7 +76,7 @@ class InlineQuery(TelegramObject): data['from_user'] = User.de_json(data.get('from'), bot) data['location'] = Location.de_json(data.get('location'), bot) - return InlineQuery(bot=bot, **data) + return cls(bot=bot, **data) def to_dict(self): """ diff --git a/telegram/inline/inlinequeryresult.py b/telegram/inline/inlinequeryresult.py index be6fc3003..fe13eca42 100644 --- a/telegram/inline/inlinequeryresult.py +++ b/telegram/inline/inlinequeryresult.py @@ -42,7 +42,3 @@ class InlineQueryResult(TelegramObject): self.id = str(id) self._id_attrs = (self.id,) - - @staticmethod - def de_json(data, bot): - return super(InlineQueryResult, InlineQueryResult).de_json(data, bot) diff --git a/telegram/inline/inlinequeryresultarticle.py b/telegram/inline/inlinequeryresultarticle.py index 1f6073062..7010ff4cf 100644 --- a/telegram/inline/inlinequeryresultarticle.py +++ b/telegram/inline/inlinequeryresultarticle.py @@ -92,12 +92,15 @@ class InlineQueryResultArticle(InlineQueryResult): if thumb_height: self.thumb_height = thumb_height - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultArticle, InlineQueryResultArticle).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultArticle, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultArticle(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultaudio.py b/telegram/inline/inlinequeryresultaudio.py index 09ccd51b5..e29ecaba4 100644 --- a/telegram/inline/inlinequeryresultaudio.py +++ b/telegram/inline/inlinequeryresultaudio.py @@ -84,12 +84,15 @@ class InlineQueryResultAudio(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultAudio, InlineQueryResultAudio).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultAudio, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultAudio(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultcachedaudio.py b/telegram/inline/inlinequeryresultcachedaudio.py index 0d25eaf3f..ac4aa0771 100644 --- a/telegram/inline/inlinequeryresultcachedaudio.py +++ b/telegram/inline/inlinequeryresultcachedaudio.py @@ -69,12 +69,15 @@ class InlineQueryResultCachedAudio(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultCachedAudio, InlineQueryResultCachedAudio).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultCachedAudio, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultCachedAudio(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultcacheddocument.py b/telegram/inline/inlinequeryresultcacheddocument.py index f9e3cd4ae..e6fbcdae8 100644 --- a/telegram/inline/inlinequeryresultcacheddocument.py +++ b/telegram/inline/inlinequeryresultcacheddocument.py @@ -73,13 +73,15 @@ class InlineQueryResultCachedDocument(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultCachedDocument, - InlineQueryResultCachedDocument).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultCachedDocument, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultCachedDocument(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultcachedgif.py b/telegram/inline/inlinequeryresultcachedgif.py index eeda9c618..abdfb1dbf 100644 --- a/telegram/inline/inlinequeryresultcachedgif.py +++ b/telegram/inline/inlinequeryresultcachedgif.py @@ -69,12 +69,15 @@ class InlineQueryResultCachedGif(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultCachedGif, InlineQueryResultCachedGif).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultCachedGif, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultCachedGif(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultcachedmpeg4gif.py b/telegram/inline/inlinequeryresultcachedmpeg4gif.py index 776e1a9d1..a8cfc1160 100644 --- a/telegram/inline/inlinequeryresultcachedmpeg4gif.py +++ b/telegram/inline/inlinequeryresultcachedmpeg4gif.py @@ -70,13 +70,15 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultCachedMpeg4Gif, - InlineQueryResultCachedMpeg4Gif).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultCachedMpeg4Gif, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultCachedMpeg4Gif(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultcachedphoto.py b/telegram/inline/inlinequeryresultcachedphoto.py index da3e6bc46..0ddc12b8c 100644 --- a/telegram/inline/inlinequeryresultcachedphoto.py +++ b/telegram/inline/inlinequeryresultcachedphoto.py @@ -73,12 +73,15 @@ class InlineQueryResultCachedPhoto(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultCachedPhoto, InlineQueryResultCachedPhoto).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultCachedPhoto, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultCachedPhoto(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultcachedsticker.py b/telegram/inline/inlinequeryresultcachedsticker.py index 39e94e7f6..c07b39db8 100644 --- a/telegram/inline/inlinequeryresultcachedsticker.py +++ b/telegram/inline/inlinequeryresultcachedsticker.py @@ -58,13 +58,15 @@ class InlineQueryResultCachedSticker(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultCachedSticker, - InlineQueryResultCachedSticker).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultCachedSticker, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultCachedSticker(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultcachedvideo.py b/telegram/inline/inlinequeryresultcachedvideo.py index 7490b4d6e..fbf33a1ee 100644 --- a/telegram/inline/inlinequeryresultcachedvideo.py +++ b/telegram/inline/inlinequeryresultcachedvideo.py @@ -72,12 +72,15 @@ class InlineQueryResultCachedVideo(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultCachedVideo, InlineQueryResultCachedVideo).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultCachedVideo, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultCachedVideo(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultcachedvoice.py b/telegram/inline/inlinequeryresultcachedvoice.py index b3f1929ef..018c57e14 100644 --- a/telegram/inline/inlinequeryresultcachedvoice.py +++ b/telegram/inline/inlinequeryresultcachedvoice.py @@ -67,12 +67,15 @@ class InlineQueryResultCachedVoice(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultCachedVoice, InlineQueryResultCachedVoice).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultCachedVoice, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultCachedVoice(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultcontact.py b/telegram/inline/inlinequeryresultcontact.py index f29e7a999..909c93a93 100644 --- a/telegram/inline/inlinequeryresultcontact.py +++ b/telegram/inline/inlinequeryresultcontact.py @@ -82,12 +82,15 @@ class InlineQueryResultContact(InlineQueryResult): if thumb_height: self.thumb_height = thumb_height - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultContact, InlineQueryResultContact).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultContact, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultContact(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultdocument.py b/telegram/inline/inlinequeryresultdocument.py index 36182c865..538bd39bc 100644 --- a/telegram/inline/inlinequeryresultdocument.py +++ b/telegram/inline/inlinequeryresultdocument.py @@ -92,12 +92,15 @@ class InlineQueryResultDocument(InlineQueryResult): if thumb_height: self.thumb_height = thumb_height - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultDocument, InlineQueryResultDocument).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultDocument, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultDocument(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultgame.py b/telegram/inline/inlinequeryresultgame.py index 71a62dde8..4176cc096 100644 --- a/telegram/inline/inlinequeryresultgame.py +++ b/telegram/inline/inlinequeryresultgame.py @@ -33,10 +33,13 @@ class InlineQueryResultGame(InlineQueryResult): if reply_markup: self.reply_markup = reply_markup - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultGame, InlineQueryResultGame).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultGame, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) - return InlineQueryResultGame(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultgif.py b/telegram/inline/inlinequeryresultgif.py index 427986b2a..6b5b878b6 100644 --- a/telegram/inline/inlinequeryresultgif.py +++ b/telegram/inline/inlinequeryresultgif.py @@ -89,12 +89,15 @@ class InlineQueryResultGif(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultGif, InlineQueryResultGif).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultGif, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultGif(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultlocation.py b/telegram/inline/inlinequeryresultlocation.py index 2483642ae..da14873e8 100644 --- a/telegram/inline/inlinequeryresultlocation.py +++ b/telegram/inline/inlinequeryresultlocation.py @@ -82,12 +82,15 @@ class InlineQueryResultLocation(InlineQueryResult): if thumb_height: self.thumb_height = thumb_height - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultLocation, InlineQueryResultLocation).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultLocation, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultLocation(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultmpeg4gif.py b/telegram/inline/inlinequeryresultmpeg4gif.py index 228079d10..7e0daca7b 100644 --- a/telegram/inline/inlinequeryresultmpeg4gif.py +++ b/telegram/inline/inlinequeryresultmpeg4gif.py @@ -90,12 +90,15 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultMpeg4Gif, InlineQueryResultMpeg4Gif).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultMpeg4Gif, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultMpeg4Gif(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultphoto.py b/telegram/inline/inlinequeryresultphoto.py index afbd7e21c..d80d3b4fc 100644 --- a/telegram/inline/inlinequeryresultphoto.py +++ b/telegram/inline/inlinequeryresultphoto.py @@ -75,12 +75,15 @@ class InlineQueryResultPhoto(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultPhoto, InlineQueryResultPhoto).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultPhoto, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultPhoto(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultvenue.py b/telegram/inline/inlinequeryresultvenue.py index b38c59871..678f607f8 100644 --- a/telegram/inline/inlinequeryresultvenue.py +++ b/telegram/inline/inlinequeryresultvenue.py @@ -59,12 +59,15 @@ class InlineQueryResultVenue(InlineQueryResult): if thumb_height: self.thumb_height = thumb_height - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultVenue, InlineQueryResultVenue).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultVenue, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultVenue(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultvideo.py b/telegram/inline/inlinequeryresultvideo.py index d40461260..75ee3a5d5 100644 --- a/telegram/inline/inlinequeryresultvideo.py +++ b/telegram/inline/inlinequeryresultvideo.py @@ -62,12 +62,15 @@ class InlineQueryResultVideo(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultVideo, InlineQueryResultVideo).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultVideo, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultVideo(**data) + return cls(**data) diff --git a/telegram/inline/inlinequeryresultvoice.py b/telegram/inline/inlinequeryresultvoice.py index 3afa05a56..8bd69eb4a 100644 --- a/telegram/inline/inlinequeryresultvoice.py +++ b/telegram/inline/inlinequeryresultvoice.py @@ -49,12 +49,15 @@ class InlineQueryResultVoice(InlineQueryResult): if input_message_content: self.input_message_content = input_message_content - @staticmethod - def de_json(data, bot): - data = super(InlineQueryResultVoice, InlineQueryResultVoice).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InlineQueryResultVoice, cls).de_json(data, bot) + + if not data: + return None data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot) data['input_message_content'] = InputMessageContent.de_json( data.get('input_message_content'), bot) - return InlineQueryResultVoice(**data) + return cls(**data) diff --git a/telegram/inline/inputcontactmessagecontent.py b/telegram/inline/inputcontactmessagecontent.py index 2174ab254..6ff01e0a6 100644 --- a/telegram/inline/inputcontactmessagecontent.py +++ b/telegram/inline/inputcontactmessagecontent.py @@ -32,6 +32,6 @@ class InputContactMessageContent(InputMessageContent): # Optionals self.last_name = last_name - @staticmethod - def de_json(data, bot): - return InputContactMessageContent(**data) + @classmethod + def de_json(cls, data, bot): + return cls(**data) diff --git a/telegram/inline/inputlocationmessagecontent.py b/telegram/inline/inputlocationmessagecontent.py index 8a3b3e76a..0eb055e0e 100644 --- a/telegram/inline/inputlocationmessagecontent.py +++ b/telegram/inline/inputlocationmessagecontent.py @@ -30,6 +30,6 @@ class InputLocationMessageContent(InputMessageContent): self.latitude = latitude self.longitude = longitude - @staticmethod - def de_json(data, bot): - return InputLocationMessageContent(**data) + @classmethod + def de_json(cls, data, bot): + return cls(**data) diff --git a/telegram/inline/inputmessagecontent.py b/telegram/inline/inputmessagecontent.py index 0938e8e50..5ae122bd0 100644 --- a/telegram/inline/inputmessagecontent.py +++ b/telegram/inline/inputmessagecontent.py @@ -25,9 +25,9 @@ from telegram import TelegramObject class InputMessageContent(TelegramObject): """Base class for Telegram InputMessageContent Objects""" - @staticmethod - def de_json(data, bot): - data = super(InputMessageContent, InputMessageContent).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(InputMessageContent, cls).de_json(data, bot) if not data: return None diff --git a/telegram/inline/inputtextmessagecontent.py b/telegram/inline/inputtextmessagecontent.py index 39545b59d..4ab825eee 100644 --- a/telegram/inline/inputtextmessagecontent.py +++ b/telegram/inline/inputtextmessagecontent.py @@ -32,6 +32,6 @@ class InputTextMessageContent(InputMessageContent): self.parse_mode = parse_mode self.disable_web_page_preview = disable_web_page_preview - @staticmethod - def de_json(data, bot): - return InputTextMessageContent(**data) + @classmethod + def de_json(cls, data, bot): + return cls(**data) diff --git a/telegram/inline/inputvenuemessagecontent.py b/telegram/inline/inputvenuemessagecontent.py index 0b3e237b3..7b360ca1f 100644 --- a/telegram/inline/inputvenuemessagecontent.py +++ b/telegram/inline/inputvenuemessagecontent.py @@ -34,6 +34,6 @@ class InputVenueMessageContent(InputMessageContent): # Optionals self.foursquare_id = foursquare_id - @staticmethod - def de_json(data, bot): - return InputVenueMessageContent(**data) + @classmethod + def de_json(cls, data, bot): + return cls(**data) diff --git a/telegram/keyboardbutton.py b/telegram/keyboardbutton.py index 48eb4bb71..566616dfb 100644 --- a/telegram/keyboardbutton.py +++ b/telegram/keyboardbutton.py @@ -40,20 +40,20 @@ class KeyboardButton(TelegramObject): self.request_contact = request_contact self.request_location = request_location - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): if not data: return None - return KeyboardButton(**data) + return cls(**data) - @staticmethod - def de_list(data, bot): + @classmethod + def de_list(cls, data, bot): if not data: return [] keyboards = list() for keyboard in data: - keyboards.append(KeyboardButton.de_json(keyboard, bot)) + keyboards.append(cls.de_json(keyboard, bot)) return keyboards diff --git a/telegram/message.py b/telegram/message.py index 7ff279dda..a49dfcf4c 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -197,8 +197,8 @@ class Message(TelegramObject): """int: Short for :attr:`Message.chat.id`""" return self.chat.id - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -210,7 +210,7 @@ class Message(TelegramObject): if not data: return None - data = super(Message, Message).de_json(data, bot) + data = super(Message, cls).de_json(data, bot) data['from_user'] = User.de_json(data.get('from'), bot) data['date'] = from_timestamp(data['date']) @@ -240,7 +240,7 @@ class Message(TelegramObject): data['invoice'] = Invoice.de_json(data.get('invoice'), bot) data['successful_payment'] = SuccessfulPayment.de_json(data.get('successful_payment'), bot) - return Message(bot=bot, **data) + return cls(bot=bot, **data) def __getitem__(self, item): if item in self.__dict__.keys(): diff --git a/telegram/messageentity.py b/telegram/messageentity.py index a0ce2fc32..754372d3a 100644 --- a/telegram/messageentity.py +++ b/telegram/messageentity.py @@ -43,16 +43,19 @@ class MessageEntity(TelegramObject): self.url = url self.user = user - @staticmethod - def de_json(data, bot): - data = super(MessageEntity, MessageEntity).de_json(data, bot) + @classmethod + def de_json(cls, data, bot): + data = super(MessageEntity, cls).de_json(data, bot) + + if not data: + return None data['user'] = User.de_json(data.get('user'), bot) - return MessageEntity(**data) + return cls(**data) - @staticmethod - def de_list(data, bot): + @classmethod + def de_list(cls, data, bot): """ Args: data (list): @@ -65,7 +68,7 @@ class MessageEntity(TelegramObject): entities = list() for entity in data: - entities.append(MessageEntity.de_json(entity, bot)) + entities.append(cls.de_json(entity, bot)) return entities diff --git a/telegram/payment/invoice.py b/telegram/payment/invoice.py index f6e4c2667..88bb8d95d 100644 --- a/telegram/payment/invoice.py +++ b/telegram/payment/invoice.py @@ -42,8 +42,8 @@ class Invoice(TelegramObject): self.currency = currency self.total_amount = total_amount - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -55,4 +55,4 @@ class Invoice(TelegramObject): if not data: return None - return Invoice(**data) + return cls(**data) diff --git a/telegram/payment/labeledprice.py b/telegram/payment/labeledprice.py index 144e99db4..8d4efe03c 100644 --- a/telegram/payment/labeledprice.py +++ b/telegram/payment/labeledprice.py @@ -34,8 +34,8 @@ class LabeledPrice(TelegramObject): self.label = label self.amount = amount - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -48,10 +48,10 @@ class LabeledPrice(TelegramObject): if not data: return None - return LabeledPrice(**data) + return cls(**data) - @staticmethod - def de_list(data, bot): + @classmethod + def de_list(cls, data, bot): """ Args: data (list): @@ -65,6 +65,6 @@ class LabeledPrice(TelegramObject): labeled_prices = list() for labeled_price in data: - labeled_prices.append(LabeledPrice.de_json(labeled_price, bot)) + labeled_prices.append(cls.de_json(labeled_price, bot)) return labeled_prices diff --git a/telegram/payment/orderinfo.py b/telegram/payment/orderinfo.py index cc4876a10..8858ccd0f 100644 --- a/telegram/payment/orderinfo.py +++ b/telegram/payment/orderinfo.py @@ -39,8 +39,8 @@ class OrderInfo(TelegramObject): self.email = email self.shipping_address = shipping_address - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -50,10 +50,10 @@ class OrderInfo(TelegramObject): telegram.OrderInfo: """ if not data: - return OrderInfo() + return cls() - data = super(OrderInfo, OrderInfo).de_json(data, bot) + data = super(OrderInfo, cls).de_json(data, bot) data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot) - return OrderInfo(**data) + return cls(**data) diff --git a/telegram/payment/precheckoutquery.py b/telegram/payment/precheckoutquery.py index 6b0732488..b8f372776 100644 --- a/telegram/payment/precheckoutquery.py +++ b/telegram/payment/precheckoutquery.py @@ -62,8 +62,8 @@ class PreCheckoutQuery(TelegramObject): self._id_attrs = (self.id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -75,12 +75,12 @@ class PreCheckoutQuery(TelegramObject): if not data: return None - data = super(PreCheckoutQuery, PreCheckoutQuery).de_json(data, bot) + data = super(PreCheckoutQuery, cls).de_json(data, bot) data['from_user'] = User.de_json(data.pop('from'), bot) data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot) - return PreCheckoutQuery(**data) + return cls(**data) def to_dict(self): """ diff --git a/telegram/payment/shippingaddress.py b/telegram/payment/shippingaddress.py index 35c6ed3e9..97d7f45ba 100644 --- a/telegram/payment/shippingaddress.py +++ b/telegram/payment/shippingaddress.py @@ -46,8 +46,8 @@ class ShippingAddress(TelegramObject): self._id_attrs = (self.country_code, self.state, self.city, self.street_line1, self.street_line2, self.post_code) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -59,4 +59,4 @@ class ShippingAddress(TelegramObject): if not data: return None - return ShippingAddress(**data) + return cls(**data) diff --git a/telegram/payment/shippingoption.py b/telegram/payment/shippingoption.py index 5fcfdf8d5..934588575 100644 --- a/telegram/payment/shippingoption.py +++ b/telegram/payment/shippingoption.py @@ -42,8 +42,8 @@ class ShippingOption(TelegramObject): self._id_attrs = (self.id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -55,11 +55,11 @@ class ShippingOption(TelegramObject): if not data: return None - data = super(ShippingOption, ShippingOption).de_json(data, bot) + data = super(ShippingOption, cls).de_json(data, bot) data['prices'] = LabeledPrice.de_list(data.get('prices'), bot) - return ShippingOption(**data) + return cls(**data) def to_dict(self): """ diff --git a/telegram/payment/shippingquery.py b/telegram/payment/shippingquery.py index 4c955a2bc..b84e33a4f 100644 --- a/telegram/payment/shippingquery.py +++ b/telegram/payment/shippingquery.py @@ -47,8 +47,8 @@ class ShippingQuery(TelegramObject): self._id_attrs = (self.id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -60,12 +60,12 @@ class ShippingQuery(TelegramObject): if not data: return None - data = super(ShippingQuery, ShippingQuery).de_json(data, bot) + data = super(ShippingQuery, cls).de_json(data, bot) data['from_user'] = User.de_json(data.pop('from'), bot) data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot) - return ShippingQuery(**data) + return cls(**data) def to_dict(self): """ diff --git a/telegram/payment/successfulpayment.py b/telegram/payment/successfulpayment.py index 3022606f7..56e31e6e5 100644 --- a/telegram/payment/successfulpayment.py +++ b/telegram/payment/successfulpayment.py @@ -58,8 +58,8 @@ class SuccessfulPayment(TelegramObject): self._id_attrs = (self.telegram_payment_charge_id, self.provider_payment_charge_id) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -71,7 +71,7 @@ class SuccessfulPayment(TelegramObject): if not data: return None - data = super(SuccessfulPayment, SuccessfulPayment).de_json(data, bot) + data = super(SuccessfulPayment, cls).de_json(data, bot) data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot) - return SuccessfulPayment(**data) + return cls(**data) diff --git a/telegram/replykeyboardmarkup.py b/telegram/replykeyboardmarkup.py index e9da71c66..9c9cccaea 100644 --- a/telegram/replykeyboardmarkup.py +++ b/telegram/replykeyboardmarkup.py @@ -54,8 +54,8 @@ class ReplyKeyboardMarkup(ReplyMarkup): self.one_time_keyboard = bool(one_time_keyboard) self.selective = bool(selective) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -67,11 +67,11 @@ class ReplyKeyboardMarkup(ReplyMarkup): if not data: return None - data = super(ReplyKeyboardMarkup, ReplyKeyboardMarkup).de_json(data, bot) + data = super(ReplyKeyboardMarkup, cls).de_json(data, bot) data['keyboard'] = [KeyboardButton.de_list(keyboard, bot) for keyboard in data['keyboard']] - return ReplyKeyboardMarkup(**data) + return cls(**data) def to_dict(self): data = super(ReplyKeyboardMarkup, self).to_dict() diff --git a/telegram/replykeyboardremove.py b/telegram/replykeyboardremove.py index 7ab537464..669d81941 100644 --- a/telegram/replykeyboardremove.py +++ b/telegram/replykeyboardremove.py @@ -46,8 +46,8 @@ class ReplyKeyboardRemove(ReplyMarkup): # Optionals self.selective = bool(selective) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -60,7 +60,7 @@ class ReplyKeyboardRemove(ReplyMarkup): if not data: return None - return ReplyKeyboardRemove(**data) + return cls(**data) class ReplyKeyboardHide(object): diff --git a/telegram/replymarkup.py b/telegram/replymarkup.py index b493d87e6..0993735ff 100644 --- a/telegram/replymarkup.py +++ b/telegram/replymarkup.py @@ -23,12 +23,4 @@ from telegram import TelegramObject class ReplyMarkup(TelegramObject): """Base class for Telegram ReplyMarkup Objects""" - - @staticmethod - def de_json(data, bot): - data = super(ReplyMarkup, ReplyMarkup).de_json(data, bot) - - if not data: - return None - - return data + pass diff --git a/telegram/update.py b/telegram/update.py index cdef6e085..f34126efe 100644 --- a/telegram/update.py +++ b/telegram/update.py @@ -89,8 +89,8 @@ class Update(TelegramObject): self._id_attrs = (self.update_id,) - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -102,7 +102,7 @@ class Update(TelegramObject): if not data: return None - data = super(Update, Update).de_json(data, bot) + data = super(Update, cls).de_json(data, bot) data['message'] = Message.de_json(data.get('message'), bot) data['edited_message'] = Message.de_json(data.get('edited_message'), bot) @@ -115,7 +115,7 @@ class Update(TelegramObject): data['channel_post'] = Message.de_json(data.get('channel_post'), bot) data['edited_channel_post'] = Message.de_json(data.get('edited_channel_post'), bot) - return Update(**data) + return cls(**data) @property def effective_user(self): diff --git a/telegram/user.py b/telegram/user.py index 0a0a1e225..5e1538aec 100644 --- a/telegram/user.py +++ b/telegram/user.py @@ -77,8 +77,8 @@ class User(TelegramObject): return '%s %s' % (self.first_name, self.last_name) return self.first_name - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -90,9 +90,9 @@ class User(TelegramObject): if not data: return None - data = super(User, User).de_json(data, bot) + data = super(User, cls).de_json(data, bot) - return User(bot=bot, **data) + return cls(bot=bot, **data) def get_profile_photos(self, *args, **kwargs): """ @@ -100,8 +100,8 @@ class User(TelegramObject): """ return self.bot.get_user_profile_photos(self.id, *args, **kwargs) - @staticmethod - def de_list(data, bot): + @classmethod + def de_list(cls, data, bot): """ Args: data (list): @@ -115,6 +115,6 @@ class User(TelegramObject): users = list() for user in data: - users.append(User.de_json(user, bot)) + users.append(cls.de_json(user, bot)) return users diff --git a/telegram/userprofilephotos.py b/telegram/userprofilephotos.py index 3e47fa331..e6be0e725 100644 --- a/telegram/userprofilephotos.py +++ b/telegram/userprofilephotos.py @@ -39,8 +39,8 @@ class UserProfilePhotos(TelegramObject): self.total_count = int(total_count) self.photos = photos - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -52,11 +52,11 @@ class UserProfilePhotos(TelegramObject): if not data: return None - data = super(UserProfilePhotos, UserProfilePhotos).de_json(data, bot) + data = super(UserProfilePhotos, cls).de_json(data, bot) data['photos'] = [PhotoSize.de_list(photo, bot) for photo in data['photos']] - return UserProfilePhotos(**data) + return cls(**data) def to_dict(self): """ diff --git a/telegram/webhookinfo.py b/telegram/webhookinfo.py index ac8c91886..8fcef72cf 100644 --- a/telegram/webhookinfo.py +++ b/telegram/webhookinfo.py @@ -58,8 +58,8 @@ class WebhookInfo(TelegramObject): self.max_connections = max_connections self.allowed_updates = allowed_updates - @staticmethod - def de_json(data, bot): + @classmethod + def de_json(cls, data, bot): """ Args: data (dict): @@ -72,4 +72,4 @@ class WebhookInfo(TelegramObject): if not data: return None - return WebhookInfo(**data) + return cls(**data) diff --git a/tests/test_animation.py b/tests/test_animation.py index 5381b808a..663ecd3c2 100644 --- a/tests/test_animation.py +++ b/tests/test_animation.py @@ -68,11 +68,11 @@ class AnimationTest(BaseTest, unittest.TestCase): animation = telegram.Animation.de_json(self.json_dict, self._bot) self.assertTrue(self.is_dict(animation.to_dict())) - self.assertEqual(animation['file_id'], self.animation_file_id) - self.assertEqual(animation['thumb'], self.thumb) - self.assertEqual(animation['file_name'], self.file_name) - self.assertEqual(animation['mime_type'], self.mime_type) - self.assertEqual(animation['file_size'], self.file_size) + self.assertEqual(animation.file_id, self.animation_file_id) + self.assertEqual(animation.thumb, self.thumb) + self.assertEqual(animation.file_name, self.file_name) + self.assertEqual(animation.mime_type, self.mime_type) + self.assertEqual(animation.file_size, self.file_size) def test_equality(self): a = telegram.Animation(self.animation_file_id)