mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #1237 from monosans/comprehension
Replace for loops with comprehensions
This commit is contained in:
commit
7914f71938
@ -359,10 +359,7 @@ class TeleBot:
|
||||
:return: array of Updates
|
||||
"""
|
||||
json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates, long_polling_timeout)
|
||||
ret = []
|
||||
for ju in json_updates:
|
||||
ret.append(types.Update.de_json(ju))
|
||||
return ret
|
||||
return [types.Update.de_json(ju) for ju in json_updates]
|
||||
|
||||
def __skip_updates(self):
|
||||
"""
|
||||
@ -832,10 +829,7 @@ class TeleBot:
|
||||
:return:
|
||||
"""
|
||||
result = apihelper.get_chat_administrators(self.token, chat_id)
|
||||
ret = []
|
||||
for r in result:
|
||||
ret.append(types.ChatMember.de_json(r))
|
||||
return ret
|
||||
return [types.ChatMember.de_json(r) for r in result]
|
||||
|
||||
def get_chat_members_count(self, chat_id: Union[int, str]) -> int:
|
||||
"""
|
||||
@ -1307,10 +1301,7 @@ class TeleBot:
|
||||
result = apihelper.send_media_group(
|
||||
self.token, chat_id, media, disable_notification, reply_to_message_id, timeout,
|
||||
allow_sending_without_reply)
|
||||
ret = []
|
||||
for msg in result:
|
||||
ret.append(types.Message.de_json(msg))
|
||||
return ret
|
||||
return [types.Message.de_json(msg) for msg in result]
|
||||
|
||||
def send_location(
|
||||
self, chat_id: Union[int, str],
|
||||
@ -1962,10 +1953,7 @@ class TeleBot:
|
||||
:return:
|
||||
"""
|
||||
result = apihelper.get_game_high_scores(self.token, user_id, chat_id, message_id, inline_message_id)
|
||||
ret = []
|
||||
for r in result:
|
||||
ret.append(types.GameHighScore.de_json(r))
|
||||
return ret
|
||||
return [types.GameHighScore.de_json(r) for r in result]
|
||||
|
||||
def send_invoice(
|
||||
self, chat_id: Union[int, str], title: str, description: str,
|
||||
|
@ -81,13 +81,10 @@ class JsonDeserializable(object):
|
||||
raise ValueError("json_type should be a json dict or string.")
|
||||
|
||||
def __str__(self):
|
||||
d = {}
|
||||
for x, y in self.__dict__.items():
|
||||
if hasattr(y, '__dict__'):
|
||||
d[x] = y.__dict__
|
||||
else:
|
||||
d[x] = y
|
||||
|
||||
d = {
|
||||
x: y.__dict__ if hasattr(y, '__dict__') else y
|
||||
for x, y in self.__dict__.items()
|
||||
}
|
||||
return str(d)
|
||||
|
||||
|
||||
|
@ -351,9 +351,10 @@ def quick_markup(values: Dict[str, Dict[str, Any]], row_width: int=2) -> types.I
|
||||
:return: InlineKeyboardMarkup
|
||||
"""
|
||||
markup = types.InlineKeyboardMarkup(row_width=row_width)
|
||||
buttons = []
|
||||
for text, kwargs in values.items():
|
||||
buttons.append(types.InlineKeyboardButton(text=text, **kwargs))
|
||||
buttons = [
|
||||
types.InlineKeyboardButton(text=text, **kwargs)
|
||||
for text, kwargs in values.items()
|
||||
]
|
||||
markup.add(*buttons)
|
||||
return markup
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user