X Tutup
Skip to content

Commit c7db9a9

Browse files
committed
Set split_before_logical_operator to True
1 parent 5a0696b commit c7db9a9

16 files changed

+76
-100
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
- repo: git://github.com/pre-commit/mirrors-yapf
2-
sha: d79d3113a991229b8f9d329e8e97b615abad91ba
2+
sha: 316b795b2f32cbe80047aff7e842b72368d5a2c1
33
hooks:
44
- id: yapf
5-
files: ^telegram/.*\.py$
5+
files: ^(examples|telegram|tests)/.*\.py$
66
- repo: git://github.com/pre-commit/pre-commit-hooks
77
sha: adbb569fe9a64ad9bce3b53a77f1bc39ef31f682
88
hooks:

examples/clibot.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#
44
# Example Bot to show some of the functionality of the library
55
# This program is dedicated to the public domain under the CC0 license.
6-
76
"""
87
This Bot uses the Updater class to handle the bot.
98
@@ -27,9 +26,8 @@
2726
from future.builtins import input
2827

2928
# Enable Logging
30-
logging.basicConfig(
31-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
32-
level=logging.INFO)
29+
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
30+
level=logging.INFO)
3331

3432
logger = logging.getLogger(__name__)
3533

@@ -58,9 +56,7 @@ def any_message(bot, update):
5856
last_chat_id = update.message.chat_id
5957

6058
logger.info("New message\nFrom: %s\nchat_id: %d\nText: %s" %
61-
(update.message.from_user,
62-
update.message.chat_id,
63-
update.message.text))
59+
(update.message.from_user, update.message.chat_id, update.message.text))
6460

6561

6662
@run_async
@@ -72,8 +68,7 @@ def message(bot, update):
7268
"""
7369

7470
sleep(2) # IO-heavy operation here
75-
bot.sendMessage(update.message.chat_id, text='Echo: %s' %
76-
update.message.text)
71+
bot.sendMessage(update.message.chat_id, text='Echo: %s' % update.message.text)
7772

7873

7974
# These handlers are for updates of type str. We use them to react to inputs
@@ -126,16 +121,14 @@ def main():
126121
# String handlers work pretty much the same. Note that we have to tell
127122
# the handler to pass the args or update_queue parameter
128123
dp.add_handler(StringCommandHandler('reply', cli_reply, pass_args=True))
129-
dp.add_handler(StringRegexHandler('[^/].*', cli_noncommand,
130-
pass_update_queue=True))
124+
dp.add_handler(StringRegexHandler('[^/].*', cli_noncommand, pass_update_queue=True))
131125

132126
# All TelegramErrors are caught for you and delivered to the error
133127
# handler(s). Other types of Errors are not caught.
134128
dp.add_error_handler(error)
135129

136130
# Start the Bot and store the update Queue, so we can insert updates
137131
update_queue = updater.start_polling(timeout=10)
138-
139132
'''
140133
# Alternatively, run with webhook:
141134
@@ -166,5 +159,6 @@ def main():
166159
elif len(text) > 0:
167160
update_queue.put(text)
168161

162+
169163
if __name__ == '__main__':
170164
main()

examples/echobot2.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#
44
# Simple Bot to reply to Telegram messages
55
# This program is dedicated to the public domain under the CC0 license.
6-
76
"""
87
This Bot uses the Updater class to handle the bot.
98
@@ -21,9 +20,8 @@
2120
import logging
2221

2322
# Enable logging
24-
logging.basicConfig(
25-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
26-
level=logging.INFO)
23+
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
24+
level=logging.INFO)
2725

2826
logger = logging.getLogger(__name__)
2927

@@ -71,5 +69,6 @@ def main():
7169
# start_polling() is non-blocking and will stop the bot gracefully.
7270
updater.idle()
7371

72+
7473
if __name__ == '__main__':
7574
main()

examples/inlinebot.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#
44
# Simple Bot to reply to Telegram messages
55
# This program is dedicated to the public domain under the CC0 license.
6-
76
"""
87
This Bot uses the Updater class to handle the bot.
98
@@ -26,9 +25,8 @@
2625
import logging
2726

2827
# Enable logging
29-
logging.basicConfig(
30-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
31-
level=logging.INFO)
28+
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
29+
level=logging.INFO)
3230

3331
logger = logging.getLogger(__name__)
3432

@@ -53,24 +51,22 @@ def inlinequery(bot, update):
5351
query = update.inline_query.query
5452
results = list()
5553

56-
results.append(InlineQueryResultArticle(
57-
id=uuid4(),
58-
title="Caps",
59-
input_message_content=InputTextMessageContent(query.upper())))
60-
61-
results.append(InlineQueryResultArticle(
62-
id=uuid4(),
63-
title="Bold",
64-
input_message_content=InputTextMessageContent(
65-
"*%s*" % escape_markdown(query),
66-
parse_mode=ParseMode.MARKDOWN)))
67-
68-
results.append(InlineQueryResultArticle(
69-
id=uuid4(),
70-
title="Italic",
71-
input_message_content=InputTextMessageContent(
72-
"_%s_" % escape_markdown(query),
73-
parse_mode=ParseMode.MARKDOWN)))
54+
results.append(InlineQueryResultArticle(id=uuid4(
55+
), title="Caps",
56+
input_message_content=InputTextMessageContent(
57+
query.upper())))
58+
59+
results.append(InlineQueryResultArticle(id=uuid4(),
60+
title="Bold",
61+
input_message_content=InputTextMessageContent(
62+
"*%s*" % escape_markdown(query),
63+
parse_mode=ParseMode.MARKDOWN)))
64+
65+
results.append(InlineQueryResultArticle(id=uuid4(),
66+
title="Italic",
67+
input_message_content=InputTextMessageContent(
68+
"_%s_" % escape_markdown(query),
69+
parse_mode=ParseMode.MARKDOWN)))
7470

7571
bot.answerInlineQuery(update.inline_query.id, results=results)
7672

@@ -104,5 +100,6 @@ def main():
104100
# start_polling() is non-blocking and will stop the bot gracefully.
105101
updater.idle()
106102

103+
107104
if __name__ == '__main__':
108105
main()

examples/inlinekeyboard_example.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212
CallbackQueryHandler, Filters
1313

1414
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - '
15-
'%(message)s',
15+
'%(message)s',
1616
level=logging.DEBUG)
1717

1818
# Define the different states a chat can be in
1919
MENU, AWAIT_CONFIRMATION, AWAIT_INPUT = range(3)
2020

2121
# Python 2 and 3 unicode differences
2222
try:
23-
YES, NO = (Emoji.THUMBS_UP_SIGN.decode('utf-8'),
24-
Emoji.THUMBS_DOWN_SIGN.decode('utf-8'))
23+
YES, NO = (Emoji.THUMBS_UP_SIGN.decode('utf-8'), Emoji.THUMBS_DOWN_SIGN.decode('utf-8'))
2524
except AttributeError:
2625
YES, NO = (Emoji.THUMBS_UP_SIGN, Emoji.THUMBS_DOWN_SIGN)
2726

@@ -58,11 +57,9 @@ def entered_value(bot, update):
5857

5958
# Save the user id and the answer to context
6059
context[user_id] = update.message.text
61-
reply_markup = InlineKeyboardMarkup(
62-
[[InlineKeyboardButton(YES, callback_data=YES),
63-
InlineKeyboardButton(NO, callback_data=NO)]])
64-
bot.sendMessage(chat_id, text="Are you sure?",
65-
reply_markup=reply_markup)
60+
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton(YES, callback_data=YES),
61+
InlineKeyboardButton(NO, callback_data=NO)]])
62+
bot.sendMessage(chat_id, text="Are you sure?", reply_markup=reply_markup)
6663

6764

6865
def confirm_value(bot, update):
@@ -82,14 +79,12 @@ def confirm_value(bot, update):
8279
values[user_id] = user_context
8380
bot.editMessageText(text="Changed value to %s." % values[user_id],
8481
chat_id=chat_id,
85-
message_id=
86-
query.message.message_id)
82+
message_id=query.message.message_id)
8783
else:
88-
bot.editMessageText(text="Alright, value is still %s."
89-
% values.get(user_id, 'not set'),
84+
bot.editMessageText(text="Alright, value is still %s." %
85+
values.get(user_id, 'not set'),
9086
chat_id=chat_id,
91-
message_id=
92-
query.message.message_id)
87+
message_id=query.message.message_id)
9388

9489

9590
def help(bot, update):

examples/legacy/echobot.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def main():
2121
except IndexError:
2222
update_id = None
2323

24-
logging.basicConfig(
25-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
24+
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
2625

2726
while True:
2827
try:
@@ -45,8 +44,7 @@ def echo(bot, update_id):
4544

4645
if message:
4746
# Reply to the message
48-
bot.sendMessage(chat_id=chat_id,
49-
text=message)
47+
bot.sendMessage(chat_id=chat_id, text=message)
5048

5149
return update_id
5250

examples/legacy/roboed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111

1212
def main():
13-
logging.basicConfig(
14-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
13+
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
1514
bot = telegram.Bot('TOKEN') # Telegram Bot Authorization Token
1615

1716
LAST_UPDATE_ID = bot.getUpdates()[-1].update_id # Get lastest update
@@ -34,5 +33,6 @@ def ed(text):
3433

3534
return data.strip()
3635

36+
3737
if __name__ == '__main__':
3838
main()

examples/state_machine_bot.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
1010

1111
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - '
12-
'%(message)s',
12+
'%(message)s',
1313
level=logging.INFO)
1414

1515
# Define the different states a chat can be in
1616
MENU, AWAIT_CONFIRMATION, AWAIT_INPUT = range(3)
1717

1818
# Python 2 and 3 unicode differences
1919
try:
20-
YES, NO = (Emoji.THUMBS_UP_SIGN.decode('utf-8'),
21-
Emoji.THUMBS_DOWN_SIGN.decode('utf-8'))
20+
YES, NO = (Emoji.THUMBS_UP_SIGN.decode('utf-8'), Emoji.THUMBS_DOWN_SIGN.decode('utf-8'))
2221
except AttributeError:
2322
YES, NO = (Emoji.THUMBS_UP_SIGN, Emoji.THUMBS_DOWN_SIGN)
2423

@@ -46,7 +45,7 @@ def set_value(bot, update):
4645
context[chat_id] = user_id # save the user id to context
4746
bot.sendMessage(chat_id,
4847
text="Please enter your settings value or send "
49-
"/cancel to abort",
48+
"/cancel to abort",
5049
reply_markup=ForceReply())
5150

5251
# If we are waiting for input and the right user answered
@@ -58,21 +57,18 @@ def set_value(bot, update):
5857
reply_markup = ReplyKeyboardMarkup(
5958
[[KeyboardButton(YES), KeyboardButton(NO)]],
6059
one_time_keyboard=True)
61-
bot.sendMessage(chat_id, text="Are you sure?",
62-
reply_markup=reply_markup)
60+
bot.sendMessage(chat_id, text="Are you sure?", reply_markup=reply_markup)
6361

6462
# If we are waiting for confirmation and the right user answered
6563
elif chat_state == AWAIT_CONFIRMATION and chat_context[0] == user_id:
6664
del state[chat_id]
6765
del context[chat_id]
6866
if text == YES:
6967
values[chat_id] = chat_context[1]
70-
bot.sendMessage(chat_id,
71-
text="Changed value to %s." % values[chat_id])
68+
bot.sendMessage(chat_id, text="Changed value to %s." % values[chat_id])
7269
else:
7370
bot.sendMessage(chat_id,
74-
text="Value not changed: %s."
75-
% values.get(chat_id, '<not set>'))
71+
text="Value not changed: %s." % values.get(chat_id, '<not set>'))
7672

7773

7874
# Handler for the /cancel command.
@@ -86,7 +82,6 @@ def cancel(bot, update):
8682
def help(bot, update):
8783
bot.sendMessage(update.message.chat_id, text="Use /set to test this bot.")
8884

89-
9085
# Create the Updater and pass it your bot's token.
9186
updater = Updater("TOKEN")
9287

examples/timerbot.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#
44
# Simple Bot to send timed Telegram messages
55
# This program is dedicated to the public domain under the CC0 license.
6-
76
"""
87
This Bot uses the Updater class to handle the bot and the JobQueue to send
98
timed messages.
@@ -22,9 +21,8 @@
2221
import logging
2322

2423
# Enable logging
25-
logging.basicConfig(
26-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
27-
level=logging.INFO)
24+
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
25+
level=logging.INFO)
2826

2927
logger = logging.getLogger(__name__)
3028
job_queue = None
@@ -33,8 +31,7 @@
3331
# Define a few command handlers. These usually take the two arguments bot and
3432
# update. Error handlers also receive the raised TelegramError object in error.
3533
def start(bot, update):
36-
bot.sendMessage(update.message.chat_id, text='Hi! Use /set <seconds> to '
37-
'set a timer')
34+
bot.sendMessage(update.message.chat_id, text='Hi! Use /set <seconds> to ' 'set a timer')
3835

3936

4037
def set(bot, update, args):
@@ -44,7 +41,8 @@ def set(bot, update, args):
4441
# args[0] should contain the time for the timer in seconds
4542
due = int(args[0])
4643
if due < 0:
47-
bot.sendMessage(chat_id, text='Sorry we can not go back to future!')
44+
bot.sendMessage(chat_id, text='Sorry we can not go back to future!')
45+
4846
def alarm(bot):
4947
""" Inner function to send the alarm message """
5048
bot.sendMessage(chat_id, text='Beep!')
@@ -88,5 +86,6 @@ def main():
8886
# start_polling() is non-blocking and will stop the bot gracefully.
8987
updater.idle()
9088

89+
9190
if __name__ == '__main__':
9291
main()

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ upload-dir = docs/build/html
1111

1212
[flake8]
1313
max-line-length = 99
14+
ignore = W503
1415

1516
[yapf]
1617
based_on_style = google
18+
split_before_logical_operator = True
1719
column_limit = 99

0 commit comments

Comments
 (0)
X Tutup