Skip to content

Commit 56b1d4f

Browse files
committed
Merge pull request python-telegram-bot#265 from python-telegram-bot/snakes
rename methods to snake_case
2 parents df16846 + 6e9f30c commit 56b1d4f

23 files changed

+225
-89
lines changed

CONTRIBUTING.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ Setting things up
2020

2121
4. Install dependencies:
2222

23-
``$ pip install -r requirements.txt``
24-
25-
``$ pip install -r requirements-dev.txt``
23+
``$ pip install -r requirements.txt -r requirements-dev.txt``
2624

2725
Finding something to do
2826
-----------------------
@@ -56,6 +54,8 @@ Here's how to make a one-off code change.
5654

5755
- You can refer to relevant issues in the commit message by writing, e.g., "#105".
5856

57+
- Your code should adhere to the `PEP 8 Style Guide`_, with the exception that we have a maximum line length of 99.
58+
5959
- For consistency, please conform to `Google Python Style Guide`_ and `Google Python Style Docstrings`_. In addition, code should be formatted consistently with other code around it.
6060

6161
- The following exceptions to the above (Google's) style guides applies:
@@ -116,7 +116,7 @@ Here's how to make a one-off code change.
116116

117117
- At the end, the reviewer will merge the pull request.
118118

119-
6. **Tidy up!** Delete the feature branch from your both your local clone and the GitHub repository:
119+
6. **Tidy up!** Delete the feature branch from both your local clone and the GitHub repository:
120120

121121
``$ git branch -D your-branch-name``
122122

@@ -127,6 +127,7 @@ Here's how to make a one-off code change.
127127
.. _`Code of Conduct`: https://www.python.org/psf/codeofconduct/
128128
.. _`issue tracker`: https://github.com/python-telegram-bot/python-telegram-bot/issues
129129
.. _`developers' mailing list`: mailto:devs@python-telegram-bot.org
130+
.. _`PEP 8 Style Guide`: https://www.python.org/dev/peps/pep-0008/
130131
.. _`Google Python Style Guide`: https://google-styleguide.googlecode.com/svn/trunk/pyguide.html
131132
.. _`Google Python Style Docstrings`: http://sphinx-doc.org/latest/ext/example_google.html
132133
.. _AUTHORS.rst: https://github.com/python-telegram-bot/python-telegram-bot/blob/master/AUTHORS.rst

README.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ _`API`
197197

198198
Note: Using the ``Bot`` class directly is the 'old' method, we have an easier way to make bots described in the next section. All of this is however still important information, even if you're using the ``telegram.ext`` submodule!
199199

200-
The API is exposed via the ``telegram.Bot`` class.
200+
The API is exposed via the ``telegram.Bot`` class. The methods have names as described in the official `Telegram Bot API <https://core.telegram.org/bots/api>`_, but equivalent snake_case methods are available for `PEP8 <https://www.python.org/dev/peps/pep-0008/>`_ enthusiasts. So for example `telegram.Bot.send_message` is the same as `telegram.Bot.sendMessage`.
201201

202202
To generate an Access Token you have to talk to `BotFather <https://telegram.me/botfather>`_ and follow a few simple steps (described `here <https://core.telegram.org/bots#6-botfather>`_).
203203

@@ -351,7 +351,7 @@ We want this function to be called on a Telegram message that contains the ``/st
351351
352352
>>> from telegram.ext import CommandHandler
353353
>>> start_handler = CommandHandler('start', start)
354-
>>> dispatcher.addHandler(start_handler)
354+
>>> dispatcher.add_handler(start_handler)
355355
356356
The last step is to tell the ``Updater`` to start working:
357357

@@ -368,7 +368,7 @@ Our bot is now up and running (go ahead and try it)! It's not doing anything yet
368368
...
369369
>>> from telegram.ext import MessageHandler, Filters
370370
>>> echo_handler = MessageHandler([Filters.text], echo)
371-
>>> dispatcher.addHandler(echo_handler)
371+
>>> dispatcher.add_handler(echo_handler)
372372
373373
Our bot should now reply to all text messages that are not a command with a message that has the same content.
374374

@@ -381,7 +381,7 @@ Let's add some functionality to our bot. We want to add the ``/caps`` command, t
381381
... bot.sendMessage(chat_id=update.message.chat_id, text=text_caps)
382382
...
383383
>>> caps_handler = CommandHandler('caps', caps, pass_args=True)
384-
>>> dispatcher.addHandler(caps_handler)
384+
>>> dispatcher.add_handler(caps_handler)
385385
386386
To enable our bot to respond to inline queries, we can add the following (you will also have to talk to BotFather):
387387

@@ -396,7 +396,7 @@ To enable our bot to respond to inline queries, we can add the following (you wi
396396
...
397397
>>> from telegram.ext import InlineQueryHandler
398398
>>> inline_caps_handler = InlineQueryHandler(inline_caps)
399-
>>> dispatcher.addHandler(inline_caps_handler)
399+
>>> dispatcher.add_handler(inline_caps_handler)
400400
401401
People might try to send commands to the bot that it doesn't understand, so we can use a ``RegexHandler`` to recognize all commands that were not recognized by the previous handlers. **Note:** This handler has to be added last, else it will be triggered before the ``CommandHandlers`` had a chance to look at the update:
402402

@@ -407,7 +407,7 @@ People might try to send commands to the bot that it doesn't understand, so we c
407407
...
408408
>>> from telegram.ext import RegexHandler
409409
>>> unknown_handler = RegexHandler(r'/.*', unknown)
410-
>>> dispatcher.addHandler(unknown_handler)
410+
>>> dispatcher.add_handler(unknown_handler)
411411
412412
If you're done playing around, stop the bot with this:
413413

examples/clibot.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
from time import sleep
2525
import logging
2626

27+
from future.builtins import input
28+
2729
# Enable Logging
2830
logging.basicConfig(
2931
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
@@ -112,24 +114,24 @@ def main():
112114
dp = updater.dispatcher
113115

114116
# This is how we add handlers for Telegram messages
115-
dp.addHandler(CommandHandler("start", start))
116-
dp.addHandler(CommandHandler("help", help))
117+
dp.add_handler(CommandHandler("start", start))
118+
dp.add_handler(CommandHandler("help", help))
117119
# Message handlers only receive updates that don't contain commands
118-
dp.addHandler(MessageHandler([Filters.text], message))
120+
dp.add_handler(MessageHandler([Filters.text], message))
119121
# Regex handlers will receive all updates on which their regex matches,
120122
# but we have to add it in a separate group, since in one group,
121123
# only one handler will be executed
122-
dp.addHandler(RegexHandler('.*', any_message), group=1)
124+
dp.add_handler(RegexHandler('.*', any_message), group=1)
123125

124126
# String handlers work pretty much the same. Note that we have to tell
125127
# the handler to pass the args or update_queue parameter
126-
dp.addHandler(StringCommandHandler('reply', cli_reply, pass_args=True))
127-
dp.addHandler(StringRegexHandler('[^/].*', cli_noncommand,
128-
pass_update_queue=True))
128+
dp.add_handler(StringCommandHandler('reply', cli_reply, pass_args=True))
129+
dp.add_handler(StringRegexHandler('[^/].*', cli_noncommand,
130+
pass_update_queue=True))
129131

130132
# All TelegramErrors are caught for you and delivered to the error
131133
# handler(s). Other types of Errors are not caught.
132-
dp.addErrorHandler(error)
134+
dp.add_error_handler(error)
133135

134136
# Start the Bot and store the update Queue, so we can insert updates
135137
update_queue = updater.start_polling(timeout=10)
@@ -153,10 +155,7 @@ def main():
153155

154156
# Start CLI-Loop
155157
while True:
156-
try:
157-
text = raw_input()
158-
except NameError:
159-
text = input()
158+
text = input()
160159

161160
# Gracefully stop the event handler
162161
if text == 'stop':

examples/echobot2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ def main():
5454
dp = updater.dispatcher
5555

5656
# on different commands - answer in Telegram
57-
dp.addHandler(CommandHandler("start", start))
58-
dp.addHandler(CommandHandler("help", help))
57+
dp.add_handler(CommandHandler("start", start))
58+
dp.add_handler(CommandHandler("help", help))
5959

6060
# on noncommand i.e message - echo the message on Telegram
61-
dp.addHandler(MessageHandler([Filters.text], echo))
61+
dp.add_handler(MessageHandler([Filters.text], echo))
6262

6363
# log all errors
64-
dp.addErrorHandler(error)
64+
dp.add_error_handler(error)
6565

6666
# Start the Bot
6767
updater.start_polling()

examples/inlinebot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ def main():
8787
dp = updater.dispatcher
8888

8989
# on different commands - answer in Telegram
90-
dp.addHandler(CommandHandler("start", start))
91-
dp.addHandler(CommandHandler("help", help))
90+
dp.add_handler(CommandHandler("start", start))
91+
dp.add_handler(CommandHandler("help", help))
9292

9393
# on noncommand i.e message - echo the message on Telegram
94-
dp.addHandler(InlineQueryHandler(inlinequery))
94+
dp.add_handler(InlineQueryHandler(inlinequery))
9595

9696
# log all errors
97-
dp.addErrorHandler(error)
97+
dp.add_error_handler(error)
9898

9999
# Start the Bot
100100
updater.start_polling()

examples/inlinekeyboard_example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ def error(bot, update, error):
105105
# The command
106106
updater.dispatcher.addHandler(CommandHandler('set', set_value))
107107
# The answer
108-
updater.dispatcher.addHandler(MessageHandler([Filters.text], entered_value))
108+
updater.dispatcher.add_handler(MessageHandler([Filters.text], entered_value))
109109
# The confirmation
110-
updater.dispatcher.addHandler(CallbackQueryHandler(confirm_value))
111-
updater.dispatcher.addHandler(CommandHandler('start', help))
112-
updater.dispatcher.addHandler(CommandHandler('help', help))
113-
updater.dispatcher.addErrorHandler(error)
110+
updater.dispatcher.add_handler(CallbackQueryHandler(confirm_value))
111+
updater.dispatcher.add_handler(CommandHandler('start', help))
112+
updater.dispatcher.add_handler(CommandHandler('help', help))
113+
updater.dispatcher.add_error_handler(error)
114114

115115
# Start the Bot
116116
updater.start_polling()

examples/state_machine_bot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ def help(bot, update):
9191
updater = Updater("TOKEN")
9292

9393
# The command
94-
updater.dispatcher.addHandler(CommandHandler('set', set_value))
94+
updater.dispatcher.add_handler(CommandHandler('set', set_value))
9595
# The answer and confirmation
96-
updater.dispatcher.addHandler(MessageHandler([Filters.text], set_value))
97-
updater.dispatcher.addHandler(CommandHandler('cancel', cancel))
98-
updater.dispatcher.addHandler(CommandHandler('start', help))
99-
updater.dispatcher.addHandler(CommandHandler('help', help))
96+
updater.dispatcher.add_handler(MessageHandler([Filters.text], set_value))
97+
updater.dispatcher.add_handler(CommandHandler('cancel', cancel))
98+
updater.dispatcher.add_handler(CommandHandler('start', help))
99+
updater.dispatcher.add_handler(CommandHandler('help', help))
100100

101101
# Start the Bot
102102
updater.start_polling()

examples/timerbot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ def main():
7373
dp = updater.dispatcher
7474

7575
# on different commands - answer in Telegram
76-
dp.addHandler(CommandHandler("start", start))
77-
dp.addHandler(CommandHandler("help", start))
78-
dp.addHandler(CommandHandler("set", set, pass_args=True))
76+
dp.add_handler(CommandHandler("start", start))
77+
dp.add_handler(CommandHandler("help", start))
78+
dp.add_handler(CommandHandler("set", set, pass_args=True))
7979

8080
# log all errors
81-
dp.addErrorHandler(error)
81+
dp.add_error_handler(error)
8282

8383
# Start the Bot
8484
updater.start_polling()

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ all_files = 1
1010
upload-dir = docs/build/html
1111

1212
[flake8]
13-
max-line-length = 99
13+
max-line-length = 99

telegram/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
"""A library that provides a Python interface to the Telegram Bot API"""
2121

22+
from sys import version_info
23+
2224
from .base import TelegramObject
2325
from .user import User
2426
from .chat import Chat
@@ -142,3 +144,9 @@
142144
'Venue',
143145
'Video',
144146
'Voice']
147+
148+
149+
if version_info < (2, 7):
150+
from warnings import warn
151+
warn("python-telegram-bot will stop supporting Python 2.6 in a future release. "
152+
"Please upgrade your Python!")

0 commit comments

Comments
 (0)