Skip to content

Commit 42eaa67

Browse files
Bibo-Joshitsnoamharshil21Poolitzer
committed
Switch to asyncio (python-telegram-bot#2731)
Co-authored-by: tsnoam <[email protected]> Co-authored-by: Harshil <[email protected]> Co-authored-by: Poolitzer <[email protected]>
1 parent a743726 commit 42eaa67

File tree

203 files changed

+22502
-14912
lines changed

Some content is hidden

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

203 files changed

+22502
-14912
lines changed

.deepsource.toml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ test_patterns = ["tests/**"]
55
exclude_patterns = [
66
"tests/**",
77
"docs/**",
8-
"telegram/vendor/**",
98
"setup.py",
109
"setup-raw.py"
1110
]

.github/CONTRIBUTING.rst

+3-8
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ Here's how to make a one-off code change.
153153
$ git commit -a
154154
$ git push origin your-branch-name
155155
156-
- If after merging you see local modified files in ``telegram/vendor/`` directory, that you didn't actually touch, that means you need to update submodules with this command:
157-
158-
.. code-block:: bash
159-
160-
$ git submodule update --init --recursive
161-
162156
- At the end, the reviewer will merge the pull request.
163157

164158
6. **Tidy up!** Delete the feature branch from both your local clone and the GitHub repository:
@@ -260,11 +254,12 @@ break the API classes. For example:
260254
261255
# GOOD
262256
def __init__(self, id, name, last_name=None, **kwargs):
263-
self.last_name = last_name
257+
self.last_name = last_name
258+
264259
265260
# BAD
266261
def __init__(self, id, name, last_name=None):
267-
self.last_name = last_name
262+
self.last_name = last_name
268263
269264
270265
.. _`Code of Conduct`: https://www.python.org/psf/codeofconduct/

.github/pull_request_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Hey! You're PRing? Cool! Please have a look at the below checklist. It's here to
88
- [ ] Created new or adapted existing unit tests
99
- [ ] Documented code changes according to the [CSI standard](https://standards.mousepawmedia.com/en/stable/csi.html)
1010
- [ ] Added myself alphabetically to `AUTHORS.rst` (optional)
11-
- [ ] Added new classes & modules to the docs
11+
- [ ] Added new classes & modules to the docs and all suitable `__all__` s
1212

1313

1414
### If the PR contains API changes (otherwise, you can delete this passage)

.github/workflows/test.yml

-9
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ jobs:
1818
fail-fast: False
1919
steps:
2020
- uses: actions/checkout@v2
21-
- name: Initialize vendored libs
22-
run:
23-
git submodule update --init --recursive
2421
- name: Set up Python ${{ matrix.python-version }}
2522
uses: actions/setup-python@v2
2623
with:
@@ -75,9 +72,6 @@ jobs:
7572
fail-fast: False
7673
steps:
7774
- uses: actions/checkout@v2
78-
- name: Initialize vendored libs
79-
run:
80-
git submodule update --init --recursive
8175
- name: Set up Python ${{ matrix.python-version }}
8276
uses: actions/setup-python@v2
8377
with:
@@ -104,9 +98,6 @@ jobs:
10498
fail-fast: False
10599
steps:
106100
- uses: actions/checkout@v2
107-
- name: Initialize vendored libs
108-
run:
109-
git submodule update --init --recursive
110101
- name: Set up Python ${{ matrix.python-version }}
111102
uses: actions/setup-python@v2
112103
with:

.gitmodules

-4
This file was deleted.

.pre-commit-config.yaml

+16-15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ repos:
99
args:
1010
- --diff
1111
- --check
12+
additional_dependencies:
13+
- click==8.0.2
1214
- repo: https://gitlab.com/pycqa/flake8
1315
rev: 4.0.1
1416
hooks:
@@ -23,7 +25,7 @@ repos:
2325
# run pylint across multiple cpu cores to speed it up-
2426
- --jobs=0 # See https://pylint.pycqa.org/en/latest/user_guide/run.html?#parallel-execution to know more
2527
additional_dependencies:
26-
- certifi
28+
- httpx >= 0.20.0,<1.0
2729
- tornado>=6.1
2830
- APScheduler==3.6.3
2931
- cachetools==4.2.2
@@ -38,25 +40,24 @@ repos:
3840
- types-ujson
3941
- types-pytz
4042
- types-cryptography
41-
- types-certifi
4243
- types-cachetools
43-
- certifi
44-
- tornado>=6.1
45-
- APScheduler==3.6.3
46-
- cachetools==4.2.2
47-
- . # this basically does `pip install -e .`
48-
- id: mypy
49-
name: mypy-examples
50-
files: ^examples/.*\.py$
51-
args:
52-
- --no-strict-optional
53-
- --follow-imports=silent
54-
additional_dependencies:
55-
- certifi
44+
- httpx >= 0.20.0,<1.0
5645
- tornado>=6.1
5746
- APScheduler==3.6.3
5847
- cachetools==4.2.2
5948
- . # this basically does `pip install -e .`
49+
- id: mypy
50+
name: mypy-examples
51+
files: ^examples/.*\.py$
52+
args:
53+
- --no-strict-optional
54+
- --follow-imports=silent
55+
additional_dependencies:
56+
- certifi
57+
- tornado>=6.1
58+
- APScheduler==3.6.3
59+
- cachetools==4.2.2
60+
- . # this basically does `pip install -e .`
6061
- repo: https://github.com/asottile/pyupgrade
6162
rev: v2.29.0
6263
hooks:

AUTHORS.rst

-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ Emeritus maintainers include
1414
`Jannes Höke <https://github.com/jh0ker>`_ (`@jh0ker <https://t.me/jh0ker>`_ on Telegram),
1515
`Noam Meltzer <https://github.com/tsnoam>`_, `Pieter Schutz <https://github.com/eldinnie>`_ and `Jasmin Bom <https://github.com/jsmnbom>`_.
1616

17-
Vendored packages
18-
-----------------
19-
20-
We're vendoring urllib3 as part of ``python-telegram-bot`` which is distributed under the MIT
21-
license. For more info, full credits & license terms, the sources can be found here:
22-
`https://github.com/python-telegram-bot/urllib3`.
23-
2417
Contributors
2518
------------
2619

README.rst

+18-8
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ Telegram API support
113113

114114
All types and methods of the Telegram Bot API **5.7** are supported.
115115

116+
===========
117+
Concurrency
118+
===========
119+
120+
Since v14.0, ``python-telegram-bot`` is built on top of Pythons ``asyncio`` module.
121+
Because ``asyncio`` is in general single-threaded, ``python-telegram-bot`` does currently not aim to be thread-safe.
122+
Noteworthy parts of ``python-telegram-bots`` API that are likely to cause issues (e.g. race conditions) when used in a multi-threaded setting include:
123+
124+
* ``telegram.ext.Application/Updater.update_queue``
125+
* ``telegram.ext.ConversationHandler.check/handle_update``
126+
* ``telegram.ext.CallbackDataCache``
127+
* ``telegram.ext.BasePersistence``
128+
* all classes in the ``telegram.ext.filters`` module that allow to add/remove allowed users/chats at runtime
129+
116130
==========
117131
Installing
118132
==========
@@ -130,12 +144,6 @@ Or you can install from source with:
130144
$ git clone https://github.com/python-telegram-bot/python-telegram-bot --recursive
131145
$ cd python-telegram-bot
132146
$ python setup.py install
133-
134-
In case you have a previously cloned local repository already, you should initialize the added urllib3 submodule before installing with:
135-
136-
.. code:: shell
137-
138-
$ git submodule update --init --recursive
139147
140148
---------------------
141149
Optional Dependencies
@@ -182,8 +190,10 @@ This library uses the ``logging`` module. To set up logging to standard output,
182190
.. code:: python
183191
184192
import logging
185-
logging.basicConfig(level=logging.DEBUG,
186-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
193+
194+
logging.basicConfig(
195+
level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
196+
)
187197
188198
at the beginning of your script.
189199

README_RAW.rst

+11-8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ Telegram API support
107107

108108
All types and methods of the Telegram Bot API **5.7** are supported.
109109

110+
===========
111+
Concurrency
112+
===========
113+
114+
Since v14.0, ``python-telegram-bot`` is built on top of Pythons ``asyncio`` module.
115+
Because ``asyncio`` is in general single-threaded, ``python-telegram-bot`` does currently not aim to be thread-safe.
116+
110117
==========
111118
Installing
112119
==========
@@ -125,12 +132,6 @@ Or you can install from source with:
125132
$ cd python-telegram-bot
126133
$ python setup-raw.py install
127134
128-
In case you have a previously cloned local repository already, you should initialize the added urllib3 submodule before installing with:
129-
130-
.. code:: shell
131-
132-
$ git submodule update --init --recursive
133-
134135
----
135136
Note
136137
----
@@ -164,8 +165,10 @@ This library uses the ``logging`` module. To set up logging to standard output,
164165
.. code:: python
165166
166167
import logging
167-
logging.basicConfig(level=logging.DEBUG,
168-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
168+
169+
logging.basicConfig(
170+
level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
171+
)
169172
170173
at the beginning of your script.
171174

docs/source/conf.py

+25-18
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@
127127
# The name of the Pygments (syntax highlighting) style to use.
128128
pygments_style = 'sphinx'
129129

130+
# Decides the language used for syntax highlighting of code blocks.
131+
highlight_language = 'python3'
132+
130133
# A list of ignored prefixes for module index sorting.
131134
#modindex_common_prefix = []
132135

@@ -155,7 +158,7 @@
155158
"announcement": 'PTB has undergone significant changes in v14. Please read the documentation '
156159
'carefully and also check out the transition guide in the '
157160
'<a href="https://github.com/python-telegram-bot/python-telegram-bot/wiki">'
158-
'wiki</a>',
161+
'wiki</a>.',
159162
}
160163

161164
# Add any paths that contain custom themes here, relative to this directory.
@@ -453,10 +456,14 @@ def _git_branch() -> str:
453456
"""Get's the current git sha if available or fall back to `master`"""
454457
try:
455458
output = subprocess.check_output( # skipcq: BAN-B607
456-
["git", "describe", "--tags"], stderr=subprocess.STDOUT
459+
["git", "describe", "--tags", "--always"], stderr=subprocess.STDOUT
457460
)
458461
return output.decode().strip()
459-
except Exception:
462+
except Exception as exc:
463+
sphinx_logger.exception(
464+
f'Failed to get a description of the current commit. Falling back to `master`.',
465+
exc_info=exc
466+
)
460467
return 'master'
461468

462469

@@ -510,7 +517,7 @@ def autodoc_process_bases(app, name, obj, option, bases: list):
510517
base = str(base)
511518

512519
# Special case because base classes are in std lib:
513-
if "_StringEnum" in base:
520+
if "StringEnum" in base == "<enum 'StringEnum'>":
514521
bases[idx] = ":class:`enum.Enum`"
515522
bases.insert(0, ':class:`str`')
516523
continue
@@ -521,24 +528,24 @@ def autodoc_process_bases(app, name, obj, option, bases: list):
521528
bases[idx] = f':class:`{base}`'
522529

523530
# Now convert `telegram._message.Message` to `telegram.Message` etc
524-
match = re.search(pattern=r"(telegram(\.ext|))\.", string=base)
525-
if match and '_utils' not in base:
526-
base = base.rstrip("'>")
527-
parts = base.rsplit(".", maxsplit=2)
531+
match = re.search(pattern=r"(telegram(\.ext|))\.[_\w\.]+", string=base)
532+
if not match or '_utils' in base:
533+
return
528534

529-
# Replace private base classes with their respective parent
530-
parts[-1] = PRIVATE_BASE_CLASSES.get(parts[-1], parts[-1])
535+
parts = match.group(0).split(".")
531536

532-
# To make sure that e.g. `telegram.ext.filters.BaseFilter` keeps the `filters` part
533-
if not parts[-2].startswith('_') and '_' not in parts[0]:
534-
base = '.'.join(parts[-2:])
535-
else:
536-
base = parts[-1]
537+
# Remove private paths
538+
for index, part in enumerate(parts):
539+
if part.startswith("_"):
540+
parts = parts[:index] + parts[-1:]
541+
break
537542

538-
# add `telegram(.ext).` back in front
539-
base = f'{match.group(0)}{base}'
543+
# Replace private base classes with their respective parent
544+
parts = [PRIVATE_BASE_CLASSES.get(part, part) for part in parts]
540545

541-
bases[idx] = f':class:`{base}`'
546+
base = ".".join(parts)
547+
548+
bases[idx] = f':class:`{base}`'
542549

543550

544551
def setup(app: Sphinx):

docs/source/index.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ Guides and tutorials
1010
====================
1111

1212
If you're just starting out with the library, we recommend following our `"Your first Bot" <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-Your-first-Bot>`_ tutorial that you can find on our `wiki <https://github.com/python-telegram-bot/python-telegram-bot/wiki>`_.
13-
On our wiki you will also find guides like how to use handlers, webhooks, emoji, proxies and much more.
13+
While being there, you will also find guides to learn how to use handlers, webhooks, proxies, making your bot persistent, and much more.
1414

1515
Examples
1616
========
1717

18-
A great way to learn is by looking at examples. Ours can be found in our `examples folder on Github <https://github.com/python-telegram-bot/python-telegram-bot/tree/master/examples>`_.
18+
A great way to learn is by looking at examples. Ours can be found in our `examples folder on Github <https://github.com/python-telegram-bot/python-telegram-bot/tree/master/examples#examples>`_.
1919

2020

2121
Reference
2222
=========
2323

2424
Below you can find a reference of all the classes and methods in python-telegram-bot.
25-
Apart from the `telegram.ext` package the objects should reflect the types defined in the `official Telegram Bot API documentation <https://core.telegram.org/bots/api>`_.
25+
Apart from the `telegram.ext` package and the `Auxiliary` modules, the objects reflect the types defined in the `official Telegram Bot API documentation <https://core.telegram.org/bots/api>`_.
2626

2727
.. toctree::
2828
telegram.ext
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
:github_url: https://github.com/python-telegram-bot/python-telegram-bot/blob/master/telegram/ext/_application.py
2+
3+
telegram.ext.Application
4+
========================
5+
6+
.. autoclass:: telegram.ext.Application
7+
:members:
8+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:github_url: https://github.com/python-telegram-bot/python-telegram-bot/blob/master/telegram/ext/_applicationbuilder.py
2+
3+
telegram.ext.ApplicationBuilder
4+
===============================
5+
6+
.. autoclass:: telegram.ext.ApplicationBuilder
7+
:members:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
:github_url: https://github.com/python-telegram-bot/python-telegram-bot/blob/master/telegram/ext/_application.py
2+
3+
telegram.ext.ApplicationHandlerStop
4+
===================================
5+
6+
.. autoclass:: telegram.ext.ApplicationHandlerStop
7+
:members:
8+
:show-inheritance:

docs/source/telegram.ext.dispatcher.rst

-8
This file was deleted.

docs/source/telegram.ext.dispatcherbuilder.rst

-7
This file was deleted.

docs/source/telegram.ext.dispatcherhandlerstop.rst

-8
This file was deleted.

0 commit comments

Comments
 (0)