GeezerVison is showing github.com — Switch to `asyncio` (#2731) · MSutt/python-telegram-bot@42eaa67
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .deepsource.toml -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,7 +5,6 @@ test_patterns = ["tests/**"] | 5 | 5 | exclude_patterns = [ | 6 | 6 | "tests/**", | 7 | 7 | "docs/**", | 8 | | - "telegram/vendor/**", | 9 | 8 | "setup.py", | 10 | 9 | "setup-raw.py" | 11 | 10 | ] | |
Collapse file Copy file name to clipboardExpand all lines: .github/CONTRIBUTING.rst +3-8Lines changed: 3 additions & 8 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -153,12 +153,6 @@ Here's how to make a one-off code change. | 153 | 153 | $ git commit -a | 154 | 154 | $ git push origin your-branch-name | 155 | 155 |
| 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 | | -
| 162 | 156 | - At the end, the reviewer will merge the pull request. | 163 | 157 |
| 164 | 158 | 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: | 260 | 254 |
| 261 | 255 | # GOOD | 262 | 256 | def __init__(self, id, name, last_name=None, **kwargs): | 263 | | - self.last_name = last_name | | 257 | + self.last_name = last_name | | 258 | +
| 264 | 259 |
| 265 | 260 | # BAD | 266 | 261 | def __init__(self, id, name, last_name=None): | 267 | | - self.last_name = last_name | | 262 | + self.last_name = last_name | 268 | 263 |
| 269 | 264 |
| 270 | 265 | .. _`Code of Conduct`: https://www.python.org/psf/codeofconduct/ | |
Collapse file Copy file name to clipboardExpand all lines: .github/pull_request_template.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -8,7 +8,7 @@ Hey! You're PRing? Cool! Please have a look at the below checklist. It's here to | 8 | 8 | - [ ] Created new or adapted existing unit tests | 9 | 9 | - [ ] Documented code changes according to the [CSI standard](https://standards.mousepawmedia.com/en/stable/csi.html) | 10 | 10 | - [ ] 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 | 12 | 12 |
| 13 | 13 |
| 14 | 14 | ### If the PR contains API changes (otherwise, you can delete this passage) | |
Collapse file Copy file name to clipboardExpand all lines: .github/workflows/test.yml -9Lines changed: 0 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 | fail-fast: False | 19 | 19 | steps: | 20 | 20 | - uses: actions/checkout@v2 | 21 | | - - name: Initialize vendored libs | 22 | | - run: | 23 | | - git submodule update --init --recursive | 24 | 21 | - name: Set up Python ${{ matrix.python-version }} | 25 | 22 | uses: actions/setup-python@v2 | 26 | 23 | with: | | 75 | 72 | fail-fast: False | 76 | 73 | steps: | 77 | 74 | - uses: actions/checkout@v2 | 78 | | - - name: Initialize vendored libs | 79 | | - run: | 80 | | - git submodule update --init --recursive | 81 | 75 | - name: Set up Python ${{ matrix.python-version }} | 82 | 76 | uses: actions/setup-python@v2 | 83 | 77 | with: | | 104 | 98 | fail-fast: False | 105 | 99 | steps: | 106 | 100 | - uses: actions/checkout@v2 | 107 | | - - name: Initialize vendored libs | 108 | | - run: | 109 | | - git submodule update --init --recursive | 110 | 101 | - name: Set up Python ${{ matrix.python-version }} | 111 | 102 | uses: actions/setup-python@v2 | 112 | 103 | with: | |
Collapse file Copy file name to clipboardExpand all lines: .gitmodules -4Lines changed: 0 additions & 4 deletions Collapse file Copy file name to clipboardExpand all lines: .pre-commit-config.yaml +16-15Lines changed: 16 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 | args: | 10 | 10 | - --diff | 11 | 11 | - --check | | 12 | + additional_dependencies: | | 13 | + - click==8.0.2 | 12 | 14 | - repo: https://gitlab.com/pycqa/flake8 | 13 | 15 | rev: 4.0.1 | 14 | 16 | hooks: | | 23 | 25 | # run pylint across multiple cpu cores to speed it up- | 24 | 26 | - --jobs=0 # See https://pylint.pycqa.org/en/latest/user_guide/run.html?#parallel-execution to know more | 25 | 27 | additional_dependencies: | 26 | | - - certifi | | 28 | + - httpx >= 0.20.0,<1.0 | 27 | 29 | - tornado>=6.1 | 28 | 30 | - APScheduler==3.6.3 | 29 | 31 | - cachetools==4.2.2 | @@ -38,25 +40,24 @@ repos: | 38 | 40 | - types-ujson | 39 | 41 | - types-pytz | 40 | 42 | - types-cryptography | 41 | | - - types-certifi | 42 | 43 | - 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 | 56 | 45 | - tornado>=6.1 | 57 | 46 | - APScheduler==3.6.3 | 58 | 47 | - cachetools==4.2.2 | 59 | 48 | - . # 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 .` | 60 | 61 | - repo: https://github.com/asottile/pyupgrade | 61 | 62 | rev: v2.29.0 | 62 | 63 | hooks: | |
Collapse file Copy file name to clipboardExpand all lines: AUTHORS.rst -7Lines changed: 0 additions & 7 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -14,13 +14,6 @@ Emeritus maintainers include | 14 | 14 | `Jannes Höke <https://github.com/jh0ker>`_ (`@jh0ker <https://t.me/jh0ker>`_ on Telegram), | 15 | 15 | `Noam Meltzer <https://github.com/tsnoam>`_, `Pieter Schutz <https://github.com/eldinnie>`_ and `Jasmin Bom <https://github.com/jsmnbom>`_. | 16 | 16 |
| 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 | | - | 24 | 17 | Contributors | 25 | 18 | ------------ | 26 | 19 |
| |
Collapse file Copy file name to clipboardExpand all lines: README.rst +18-8Lines changed: 18 additions & 8 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -113,6 +113,20 @@ Telegram API support | 113 | 113 |
| 114 | 114 | All types and methods of the Telegram Bot API **5.7** are supported. | 115 | 115 |
| | 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 | + | 116 | 130 | ========== | 117 | 131 | Installing | 118 | 132 | ========== | @@ -130,12 +144,6 @@ Or you can install from source with: | 130 | 144 | $ git clone https://github.com/python-telegram-bot/python-telegram-bot --recursive | 131 | 145 | $ cd python-telegram-bot | 132 | 146 | $ 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 | 139 | 147 |
| 140 | 148 | --------------------- | 141 | 149 | Optional Dependencies | @@ -182,8 +190,10 @@ This library uses the ``logging`` module. To set up logging to standard output, | 182 | 190 | .. code:: python | 183 | 191 |
| 184 | 192 | 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 | + ) | 187 | 197 |
| 188 | 198 | at the beginning of your script. | 189 | 199 |
| |
Collapse file Copy file name to clipboardExpand all lines: README_RAW.rst +11-8Lines changed: 11 additions & 8 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -107,6 +107,13 @@ Telegram API support | 107 | 107 |
| 108 | 108 | All types and methods of the Telegram Bot API **5.7** are supported. | 109 | 109 |
| | 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 | + | 110 | 117 | ========== | 111 | 118 | Installing | 112 | 119 | ========== | @@ -125,12 +132,6 @@ Or you can install from source with: | 125 | 132 | $ cd python-telegram-bot | 126 | 133 | $ python setup-raw.py install | 127 | 134 |
| 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 | | -
| 134 | 135 | ---- | 135 | 136 | Note | 136 | 137 | ---- | @@ -164,8 +165,10 @@ This library uses the ``logging`` module. To set up logging to standard output, | 164 | 165 | .. code:: python | 165 | 166 |
| 166 | 167 | 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 | + ) | 169 | 172 |
| 170 | 173 | at the beginning of your script. | 171 | 174 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs/source/conf.py +25-18Lines changed: 25 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 127 | 127 | # The name of the Pygments (syntax highlighting) style to use. | 128 | 128 | pygments_style = 'sphinx' | 129 | 129 |
| | 130 | +# Decides the language used for syntax highlighting of code blocks. | | 131 | +highlight_language = 'python3' | | 132 | + | 130 | 133 | # A list of ignored prefixes for module index sorting. | 131 | 134 | #modindex_common_prefix = [] | 132 | 135 |
| | 155 | 158 | "announcement": 'PTB has undergone significant changes in v14. Please read the documentation ' | 156 | 159 | 'carefully and also check out the transition guide in the ' | 157 | 160 | '<a href="https://github.com/python-telegram-bot/python-telegram-bot/wiki">' | 158 | | - 'wiki</a>', | | 161 | + 'wiki</a>.', | 159 | 162 | } | 160 | 163 |
| 161 | 164 | # Add any paths that contain custom themes here, relative to this directory. | @@ -453,10 +456,14 @@ def _git_branch() -> str: | 453 | 456 | """Get's the current git sha if available or fall back to `master`""" | 454 | 457 | try: | 455 | 458 | output = subprocess.check_output( # skipcq: BAN-B607 | 456 | | - ["git", "describe", "--tags"], stderr=subprocess.STDOUT | | 459 | + ["git", "describe", "--tags", "--always"], stderr=subprocess.STDOUT | 457 | 460 | ) | 458 | 461 | 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 | + ) | 460 | 467 | return 'master' | 461 | 468 |
| 462 | 469 |
| @@ -510,7 +517,7 @@ def autodoc_process_bases(app, name, obj, option, bases: list): | 510 | 517 | base = str(base) | 511 | 518 |
| 512 | 519 | # Special case because base classes are in std lib: | 513 | | - if "_StringEnum" in base: | | 520 | + if "StringEnum" in base == "<enum 'StringEnum'>": | 514 | 521 | bases[idx] = ":class:`enum.Enum`" | 515 | 522 | bases.insert(0, ':class:`str`') | 516 | 523 | continue | @@ -521,24 +528,24 @@ def autodoc_process_bases(app, name, obj, option, bases: list): | 521 | 528 | bases[idx] = f':class:`{base}`' | 522 | 529 |
| 523 | 530 | # 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 | 528 | 534 |
| 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(".") | 531 | 536 |
| 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 | 537 | 542 |
| 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] | 540 | 545 |
| 541 | | - bases[idx] = f':class:`{base}`' | | 546 | + base = ".".join(parts) | | 547 | + | | 548 | + bases[idx] = f':class:`{base}`' | 542 | 549 |
| 543 | 550 |
| 544 | 551 | def setup(app: Sphinx): | |
|