From 9fd37b7bd23b0ed4f28c4a8bce49e0f2a9907c20 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Mon, 28 Jul 2025 17:31:36 -0700 Subject: [PATCH 1/7] Remove pyupgrade, black, flake8 and isort --- .pre-commit-config.yaml | 32 +++++--------------------------- pyproject.toml | 9 --------- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4b091946e44..d8dfbb3c1d9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,8 +7,9 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.12.2' + rev: 'v0.12.5' hooks: + # Run the linter: - id: ruff name: ruff additional_dependencies: @@ -17,17 +18,8 @@ repos: - APScheduler~=3.10.4 - cachetools>=5.3.3,<5.5.0 - aiolimiter~=1.1,<1.3 -- repo: https://github.com/psf/black-pre-commit-mirror - rev: 25.1.0 - hooks: - - id: black - args: - - --diff - - --check -- repo: https://github.com/PyCQA/flake8 - rev: 7.3.0 - hooks: - - id: flake8 + # Run the formatter: + - id: ruff-format - repo: https://github.com/PyCQA/pylint rev: v3.3.7 hooks: @@ -66,18 +58,4 @@ repos: - tornado~=6.4 - APScheduler~=3.10.4 - cachetools>=5.3.3,<5.5.0 - - . # this basically does `pip install -e .` -- repo: https://github.com/asottile/pyupgrade - rev: v3.20.0 - hooks: - - id: pyupgrade - args: - - --py39-plus -- repo: https://github.com/pycqa/isort - rev: 6.0.1 - hooks: - - id: isort - name: isort - args: - - --diff - - --check + - . # this basically does `pip install -e .` \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 181fb0e0ed3..a333c0f662e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -156,15 +156,6 @@ packages = ["src/telegram"] sys_path = "changes" chango_instance = { name= "chango_instance", module = "config" } -# BLACK: -[tool.black] -line-length = 99 - -# ISORT: -[tool.isort] # black config -profile = "black" -line_length = 99 - # RUFF: [tool.ruff] line-length = 99 From fb46ef77104858c41ac6941b3922475fe82069bb Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Mon, 28 Jul 2025 18:38:33 -0700 Subject: [PATCH 2/7] Run ruff formatter and linter --- .pre-commit-config.yaml | 12 ++--- docs/auxil/link_code.py | 1 + examples/arbitrarycallbackdatabot.py | 1 + examples/customwebhookbot/djangobot.py | 1 + examples/customwebhookbot/flaskbot.py | 1 + examples/customwebhookbot/quartbot.py | 1 + examples/customwebhookbot/starlettebot.py | 1 + examples/errorhandlerbot.py | 1 + examples/inlinebot.py | 1 + examples/inlinekeyboard.py | 1 + examples/inlinekeyboard2.py | 1 + examples/passportbot.py | 1 + examples/pollbot.py | 1 + examples/rawapibot.py | 1 + examples/webappbot.py | 1 + src/telegram/_birthdate.py | 1 + src/telegram/_bot.py | 3 +- src/telegram/_botcommandscope.py | 1 + src/telegram/_botdescription.py | 1 + src/telegram/_botname.py | 1 + src/telegram/_business.py | 1 + src/telegram/_callbackquery.py | 1 + src/telegram/_chat.py | 1 + src/telegram/_chatadministratorrights.py | 1 + src/telegram/_chatbackground.py | 1 + src/telegram/_chatboost.py | 1 + src/telegram/_chatfullinfo.py | 1 + src/telegram/_chatinvitelink.py | 1 + src/telegram/_chatjoinrequest.py | 1 + src/telegram/_chatmemberupdated.py | 1 + src/telegram/_chatpermissions.py | 1 + src/telegram/_checklists.py | 1 + src/telegram/_copytextbutton.py | 1 + src/telegram/_dice.py | 1 + src/telegram/_directmessagepricechanged.py | 1 - src/telegram/_files/_basemedium.py | 1 + src/telegram/_files/_basethumbedmedium.py | 1 + src/telegram/_files/animation.py | 1 + src/telegram/_files/audio.py | 1 + src/telegram/_files/chatphoto.py | 1 + src/telegram/_files/contact.py | 1 + src/telegram/_files/document.py | 1 + src/telegram/_files/file.py | 1 + src/telegram/_files/inputmedia.py | 1 + src/telegram/_files/sticker.py | 1 + src/telegram/_files/video.py | 1 + src/telegram/_files/voice.py | 1 + src/telegram/_forumtopic.py | 1 + src/telegram/_games/game.py | 1 + src/telegram/_gifts.py | 1 + src/telegram/_giveaway.py | 3 +- src/telegram/_inline/inlinekeyboardmarkup.py | 1 + .../_inline/inlinequeryresultaudio.py | 1 + .../_inline/inlinequeryresultcachedaudio.py | 1 + .../inlinequeryresultcacheddocument.py | 1 + .../_inline/inlinequeryresultcachedgif.py | 1 + .../inlinequeryresultcachedmpeg4gif.py | 1 + .../_inline/inlinequeryresultcachedphoto.py | 1 + .../_inline/inlinequeryresultcachedvideo.py | 1 + .../_inline/inlinequeryresultcachedvoice.py | 1 + .../_inline/inlinequeryresultdocument.py | 1 + src/telegram/_inline/inlinequeryresultgame.py | 1 + src/telegram/_inline/inlinequeryresultgif.py | 1 + .../_inline/inlinequeryresultmpeg4gif.py | 1 + .../_inline/inlinequeryresultphoto.py | 1 + .../_inline/inlinequeryresultvideo.py | 1 + .../_inline/inlinequeryresultvoice.py | 1 + .../_inline/inputcontactmessagecontent.py | 1 + .../_inline/inputinvoicemessagecontent.py | 1 + .../_inline/inputtextmessagecontent.py | 1 + .../_inline/inputvenuemessagecontent.py | 1 + src/telegram/_inline/preparedinlinemessage.py | 1 + src/telegram/_inputchecklist.py | 1 + src/telegram/_keyboardbuttonpolltype.py | 1 + src/telegram/_linkpreviewoptions.py | 1 - src/telegram/_loginurl.py | 1 + src/telegram/_menubutton.py | 1 + src/telegram/_messageorigin.py | 1 + src/telegram/_messagereactionupdated.py | 1 + src/telegram/_paidmessagepricechanged.py | 1 + .../_passport/encryptedpassportelement.py | 1 + src/telegram/_passport/passportdata.py | 1 + src/telegram/_payment/shippingoption.py | 1 + src/telegram/_payment/stars/affiliateinfo.py | 1 + .../_payment/stars/revenuewithdrawalstate.py | 1 + src/telegram/_payment/stars/staramount.py | 1 - .../_payment/stars/transactionpartner.py | 1 + src/telegram/_poll.py | 1 + src/telegram/_proximityalerttriggered.py | 1 + src/telegram/_reply.py | 1 + src/telegram/_replykeyboardremove.py | 1 + src/telegram/_sentwebappmessage.py | 1 + src/telegram/_shared.py | 1 + src/telegram/_switchinlinequerychosenchat.py | 1 + src/telegram/_telegramobject.py | 4 +- src/telegram/_uniquegift.py | 1 + src/telegram/_user.py | 1 + src/telegram/_userprofilephotos.py | 1 + src/telegram/_utils/argumentparsing.py | 1 + src/telegram/_utils/datetime.py | 5 +- src/telegram/_utils/defaultvalue.py | 1 + src/telegram/_utils/entities.py | 1 + src/telegram/_utils/enum.py | 1 + src/telegram/_utils/logging.py | 1 + src/telegram/_utils/markup.py | 1 + src/telegram/_utils/repr.py | 1 + src/telegram/_utils/types.py | 1 + src/telegram/_utils/usernames.py | 1 + src/telegram/_utils/warnings.py | 1 + src/telegram/_utils/warnings_transition.py | 1 + src/telegram/_videochat.py | 1 + src/telegram/_writeaccessallowed.py | 1 + src/telegram/ext/_aioratelimiter.py | 1 + src/telegram/ext/_application.py | 5 +- src/telegram/ext/_applicationbuilder.py | 1 + src/telegram/ext/_basepersistence.py | 1 + src/telegram/ext/_baseratelimiter.py | 1 + src/telegram/ext/_baseupdateprocessor.py | 1 + src/telegram/ext/_callbackdatacache.py | 1 + src/telegram/ext/_contexttypes.py | 1 + src/telegram/ext/_defaults.py | 1 + src/telegram/ext/_dictpersistence.py | 1 + src/telegram/ext/_extbot.py | 1 + src/telegram/ext/_handlers/basehandler.py | 1 + .../_handlers/businessconnectionhandler.py | 1 + .../businessmessagesdeletedhandler.py | 1 + .../ext/_handlers/callbackqueryhandler.py | 1 + .../ext/_handlers/chatmemberhandler.py | 1 + .../_handlers/choseninlineresulthandler.py | 1 + src/telegram/ext/_handlers/commandhandler.py | 1 + .../ext/_handlers/conversationhandler.py | 1 + .../ext/_handlers/inlinequeryhandler.py | 1 + src/telegram/ext/_handlers/messagehandler.py | 1 + .../ext/_handlers/pollanswerhandler.py | 1 - src/telegram/ext/_handlers/pollhandler.py | 1 - .../ext/_handlers/precheckoutqueryhandler.py | 1 - src/telegram/ext/_handlers/prefixhandler.py | 1 + .../ext/_handlers/shippingqueryhandler.py | 1 - src/telegram/ext/_jobqueue.py | 1 + src/telegram/ext/_picklepersistence.py | 1 + src/telegram/ext/_utils/_update_parsing.py | 1 + src/telegram/ext/_utils/asyncio.py | 1 + src/telegram/ext/_utils/networkloop.py | 1 + src/telegram/ext/_utils/stack.py | 1 + src/telegram/ext/_utils/trackingdict.py | 1 + src/telegram/ext/_utils/types.py | 1 + src/telegram/request/_baserequest.py | 1 + src/telegram/request/_httpxrequest.py | 1 + src/telegram/request/_requestdata.py | 1 + src/telegram/request/_requestparameter.py | 1 + tests/_files/conftest.py | 1 + tests/_files/test_inputprofilephoto.py | 1 - tests/_files/test_inputstorycontent.py | 1 - .../test_inputinvoicemessagecontent.py | 1 - tests/_passport/test_no_passport.py | 1 + tests/_utils/test_datetime.py | 6 +-- tests/auxil/bot_method_checks.py | 1 + tests/auxil/ci_bots.py | 5 +- tests/auxil/pytest_classes.py | 1 + tests/ext/test_application.py | 13 ++--- tests/ext/test_applicationbuilder.py | 12 +---- tests/ext/test_baseupdateprocessor.py | 1 + tests/ext/test_callbackdatacache.py | 12 ++--- tests/ext/test_conversationhandler.py | 7 +-- tests/ext/test_filters.py | 6 +-- tests/ext/test_picklepersistence.py | 6 +-- tests/ext/test_ratelimiter.py | 1 + tests/ext/test_updater.py | 5 -- tests/request/test_request.py | 18 +++++-- tests/test_bot.py | 24 ++++----- tests/test_botdescription.py | 6 +-- tests/test_checklists.py | 12 ++--- tests/test_constants.py | 12 ++--- tests/test_copytextbutton.py | 6 +-- tests/test_enum_types.py | 3 +- tests/test_forum.py | 8 ++- tests/test_gifts.py | 6 +-- tests/test_giveaway.py | 18 +++---- tests/test_inlinequeryresultsbutton.py | 1 - tests/test_inputchecklist.py | 12 ++--- tests/test_keyboardbuttonrequest.py | 6 +-- tests/test_maybeinaccessiblemessage.py | 6 +-- tests/test_message.py | 3 +- tests/test_modules.py | 1 + tests/test_official/test_official.py | 54 +++++++++---------- tests/test_paidmessagepricechanged.py | 6 +-- tests/test_poll.py | 7 ++- tests/test_reaction.py | 6 +-- tests/test_reply.py | 12 ++--- tests/test_telegramobject.py | 6 +-- tests/test_uniquegift.py | 30 +++++------ tests/test_videochat.py | 1 - 192 files changed, 323 insertions(+), 198 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d8dfbb3c1d9..b38baf641d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,12 +12,12 @@ repos: # Run the linter: - id: ruff name: ruff - additional_dependencies: - - httpx~=0.27 - - tornado~=6.4 - - APScheduler~=3.10.4 - - cachetools>=5.3.3,<5.5.0 - - aiolimiter~=1.1,<1.3 + # additional_dependencies: + # - httpx~=0.27 + # - tornado~=6.4 + # - APScheduler~=3.10.4 + # - cachetools>=5.3.3,<5.5.0 + # - aiolimiter~=1.1,<1.3 # Run the formatter: - id: ruff-format - repo: https://github.com/PyCQA/pylint diff --git a/docs/auxil/link_code.py b/docs/auxil/link_code.py index 63dd3fad86a..fc0886b3d5c 100644 --- a/docs/auxil/link_code.py +++ b/docs/auxil/link_code.py @@ -19,6 +19,7 @@ to link to the correct files & lines on github. Can be simplified once https://github.com/sphinx-doc/sphinx/issues/1556 is closed """ + import subprocess from pathlib import Path diff --git a/examples/arbitrarycallbackdatabot.py b/examples/arbitrarycallbackdatabot.py index 64971817bfb..4e5fbd877c1 100644 --- a/examples/arbitrarycallbackdatabot.py +++ b/examples/arbitrarycallbackdatabot.py @@ -11,6 +11,7 @@ To use arbitrary callback data, you must install PTB via `pip install "python-telegram-bot[callback-data]"` """ + import logging from typing import cast diff --git a/examples/customwebhookbot/djangobot.py b/examples/customwebhookbot/djangobot.py index 0e4c9c12ad1..3bbd3dd1640 100644 --- a/examples/customwebhookbot/djangobot.py +++ b/examples/customwebhookbot/djangobot.py @@ -13,6 +13,7 @@ You may also need to change the `listen` value in the uvicorn configuration to match your setup. Press Ctrl-C on the command line or send a signal to the process to stop the bot. """ + import asyncio import html import json diff --git a/examples/customwebhookbot/flaskbot.py b/examples/customwebhookbot/flaskbot.py index 66c9da6661a..d129004cd65 100644 --- a/examples/customwebhookbot/flaskbot.py +++ b/examples/customwebhookbot/flaskbot.py @@ -13,6 +13,7 @@ You may also need to change the `listen` value in the uvicorn configuration to match your setup. Press Ctrl-C on the command line or send a signal to the process to stop the bot. """ + import asyncio import html import logging diff --git a/examples/customwebhookbot/quartbot.py b/examples/customwebhookbot/quartbot.py index 71ab83f5c8c..6db1035dbd9 100644 --- a/examples/customwebhookbot/quartbot.py +++ b/examples/customwebhookbot/quartbot.py @@ -13,6 +13,7 @@ You may also need to change the `listen` value in the uvicorn configuration to match your setup. Press Ctrl-C on the command line or send a signal to the process to stop the bot. """ + import asyncio import html import logging diff --git a/examples/customwebhookbot/starlettebot.py b/examples/customwebhookbot/starlettebot.py index 08397ebd729..26ee12fe2ad 100644 --- a/examples/customwebhookbot/starlettebot.py +++ b/examples/customwebhookbot/starlettebot.py @@ -13,6 +13,7 @@ You may also need to change the `listen` value in the uvicorn configuration to match your setup. Press Ctrl-C on the command line or send a signal to the process to stop the bot. """ + import asyncio import html import logging diff --git a/examples/errorhandlerbot.py b/examples/errorhandlerbot.py index 25885bd6fd3..450b18eb284 100644 --- a/examples/errorhandlerbot.py +++ b/examples/errorhandlerbot.py @@ -3,6 +3,7 @@ # This program is dedicated to the public domain under the CC0 license. """This is a very simple example on how one could implement a custom error handler.""" + import html import json import logging diff --git a/examples/inlinebot.py b/examples/inlinebot.py index 566cfe14bea..1805e3b4dd7 100644 --- a/examples/inlinebot.py +++ b/examples/inlinebot.py @@ -14,6 +14,7 @@ Press Ctrl-C on the command line or send a signal to the process to stop the bot. """ + import logging from html import escape from uuid import uuid4 diff --git a/examples/inlinekeyboard.py b/examples/inlinekeyboard.py index ee82c4e81f6..8fcc53af8a3 100644 --- a/examples/inlinekeyboard.py +++ b/examples/inlinekeyboard.py @@ -6,6 +6,7 @@ Basic example for a bot that uses inline keyboards. For an in-depth explanation, check out https://github.com/python-telegram-bot/python-telegram-bot/wiki/InlineKeyboard-Example. """ + import logging from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update diff --git a/examples/inlinekeyboard2.py b/examples/inlinekeyboard2.py index 639fde4dd1c..2a766be70e8 100644 --- a/examples/inlinekeyboard2.py +++ b/examples/inlinekeyboard2.py @@ -14,6 +14,7 @@ Send /start to initiate the conversation. Press Ctrl-C on the command line to stop the bot. """ + import logging from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update diff --git a/examples/passportbot.py b/examples/passportbot.py index c883e0f76fe..6b012b583c9 100644 --- a/examples/passportbot.py +++ b/examples/passportbot.py @@ -14,6 +14,7 @@ To use Telegram Passport, you must install PTB via `pip install "python-telegram-bot[passport]"` """ + import logging from pathlib import Path diff --git a/examples/pollbot.py b/examples/pollbot.py index 71446e9a81d..c4e296e1c1f 100644 --- a/examples/pollbot.py +++ b/examples/pollbot.py @@ -7,6 +7,7 @@ poll/quiz the bot generates. The preview command generates a closed poll/quiz, exactly like the one the user sends the bot """ + import logging from telegram import ( diff --git a/examples/rawapibot.py b/examples/rawapibot.py index 34ac964c4b7..b668046f835 100644 --- a/examples/rawapibot.py +++ b/examples/rawapibot.py @@ -5,6 +5,7 @@ on the telegram.ext bot framework. This program is dedicated to the public domain under the CC0 license. """ + import asyncio import contextlib import datetime as dtm diff --git a/examples/webappbot.py b/examples/webappbot.py index f9bb30eb0ad..6b095d00726 100644 --- a/examples/webappbot.py +++ b/examples/webappbot.py @@ -8,6 +8,7 @@ Currently only showcases starting the WebApp via a KeyboardButton, as all other methods would require a bot token. """ + import json import logging diff --git a/src/telegram/_birthdate.py b/src/telegram/_birthdate.py index 643af05fc7d..8a19f12b3ef 100644 --- a/src/telegram/_birthdate.py +++ b/src/telegram/_birthdate.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Birthday.""" + import datetime as dtm from typing import Optional diff --git a/src/telegram/_bot.py b/src/telegram/_bot.py index c5ea0a7b182..39056b41581 100644 --- a/src/telegram/_bot.py +++ b/src/telegram/_bot.py @@ -3620,8 +3620,7 @@ def _effective_inline_results( next_offset_int = current_offset_int + 1 next_offset = str(next_offset_int) effective_results = results[ - current_offset_int - * InlineQueryLimit.RESULTS : next_offset_int + current_offset_int * InlineQueryLimit.RESULTS : next_offset_int * InlineQueryLimit.RESULTS ] else: diff --git a/src/telegram/_botcommandscope.py b/src/telegram/_botcommandscope.py index dbce54c32c4..95b96d12e73 100644 --- a/src/telegram/_botcommandscope.py +++ b/src/telegram/_botcommandscope.py @@ -18,6 +18,7 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. # pylint: disable=redefined-builtin """This module contains objects representing Telegram bot command scopes.""" + from typing import TYPE_CHECKING, Final, Optional, Union from telegram import constants diff --git a/src/telegram/_botdescription.py b/src/telegram/_botdescription.py index 9f53ef1be86..77297a5c996 100644 --- a/src/telegram/_botdescription.py +++ b/src/telegram/_botdescription.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains two objects that represent a Telegram bots (short) description.""" + from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_botname.py b/src/telegram/_botname.py index a297027eae6..23af9223da0 100644 --- a/src/telegram/_botname.py +++ b/src/telegram/_botname.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represent a Telegram bots name.""" + from typing import Final, Optional from telegram import constants diff --git a/src/telegram/_business.py b/src/telegram/_business.py index e2eaf4e64e4..825ec5c736f 100644 --- a/src/telegram/_business.py +++ b/src/telegram/_business.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/] """This module contains the Telegram Business related classes.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_callbackquery.py b/src/telegram/_callbackquery.py index 39c19e6f3f0..18b5980e6c6 100644 --- a/src/telegram/_callbackquery.py +++ b/src/telegram/_callbackquery.py @@ -18,6 +18,7 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. # pylint: disable=redefined-builtin """This module contains an object that represents a Telegram CallbackQuery""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Final, Optional, Union diff --git a/src/telegram/_chat.py b/src/telegram/_chat.py index 818b01c2ed2..53e4934523b 100644 --- a/src/telegram/_chat.py +++ b/src/telegram/_chat.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Chat.""" + import datetime as dtm from collections.abc import Sequence from html import escape diff --git a/src/telegram/_chatadministratorrights.py b/src/telegram/_chatadministratorrights.py index 6b6c43715eb..f5b75e786ac 100644 --- a/src/telegram/_chatadministratorrights.py +++ b/src/telegram/_chatadministratorrights.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the class which represents a Telegram ChatAdministratorRights.""" + from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_chatbackground.py b/src/telegram/_chatbackground.py index a4bbf5b0836..3a05b3d9fa8 100644 --- a/src/telegram/_chatbackground.py +++ b/src/telegram/_chatbackground.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains objects related to chat backgrounds.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Final, Optional diff --git a/src/telegram/_chatboost.py b/src/telegram/_chatboost.py index 678b713afc3..0c41cd75f25 100644 --- a/src/telegram/_chatboost.py +++ b/src/telegram/_chatboost.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram ChatBoosts.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Final, Optional diff --git a/src/telegram/_chatfullinfo.py b/src/telegram/_chatfullinfo.py index e6e1e5f0d9b..67ef717832e 100644 --- a/src/telegram/_chatfullinfo.py +++ b/src/telegram/_chatfullinfo.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram ChatFullInfo.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_chatinvitelink.py b/src/telegram/_chatinvitelink.py index cf973a20281..9eba8ee30a5 100644 --- a/src/telegram/_chatinvitelink.py +++ b/src/telegram/_chatinvitelink.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents an invite link for a chat.""" + import datetime as dtm from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_chatjoinrequest.py b/src/telegram/_chatjoinrequest.py index 048b6a80b5d..c7d47d8c0b8 100644 --- a/src/telegram/_chatjoinrequest.py +++ b/src/telegram/_chatjoinrequest.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram ChatJoinRequest.""" + import datetime as dtm from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_chatmemberupdated.py b/src/telegram/_chatmemberupdated.py index 5aeab80a1fa..0a25f9eadd8 100644 --- a/src/telegram/_chatmemberupdated.py +++ b/src/telegram/_chatmemberupdated.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram ChatMemberUpdated.""" + import datetime as dtm from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_chatpermissions.py b/src/telegram/_chatpermissions.py index e70e858f291..947286c76f8 100644 --- a/src/telegram/_chatpermissions.py +++ b/src/telegram/_chatpermissions.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram ChatPermission.""" + from typing import TYPE_CHECKING, Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_checklists.py b/src/telegram/_checklists.py index 3726f60f149..e062e32aa3a 100644 --- a/src/telegram/_checklists.py +++ b/src/telegram/_checklists.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an objects related to Telegram checklists.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_copytextbutton.py b/src/telegram/_copytextbutton.py index 4a3cdb90590..453588d40d2 100644 --- a/src/telegram/_copytextbutton.py +++ b/src/telegram/_copytextbutton.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram CopyTextButton.""" + from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_dice.py b/src/telegram/_dice.py index a549aefb09d..a325f2984be 100644 --- a/src/telegram/_dice.py +++ b/src/telegram/_dice.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Dice.""" + from typing import Final, Optional from telegram import constants diff --git a/src/telegram/_directmessagepricechanged.py b/src/telegram/_directmessagepricechanged.py index ae50f06adec..36462bfac23 100644 --- a/src/telegram/_directmessagepricechanged.py +++ b/src/telegram/_directmessagepricechanged.py @@ -18,7 +18,6 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Direct Message Price.""" - from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_files/_basemedium.py b/src/telegram/_files/_basemedium.py index 4dd76b10e4b..314e5300122 100644 --- a/src/telegram/_files/_basemedium.py +++ b/src/telegram/_files/_basemedium.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """Common base class for media objects""" + from typing import TYPE_CHECKING, Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_files/_basethumbedmedium.py b/src/telegram/_files/_basethumbedmedium.py index 2008475c2f2..f9d8dd3624c 100644 --- a/src/telegram/_files/_basethumbedmedium.py +++ b/src/telegram/_files/_basethumbedmedium.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """Common base class for media objects with thumbnails""" + from typing import TYPE_CHECKING, Optional, TypeVar from telegram._files._basemedium import _BaseMedium diff --git a/src/telegram/_files/animation.py b/src/telegram/_files/animation.py index e2f0315d10b..d6537b4c339 100644 --- a/src/telegram/_files/animation.py +++ b/src/telegram/_files/animation.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Animation.""" + import datetime as dtm from typing import Optional, Union diff --git a/src/telegram/_files/audio.py b/src/telegram/_files/audio.py index 0ae3588e1d1..3453abb6cb4 100644 --- a/src/telegram/_files/audio.py +++ b/src/telegram/_files/audio.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Audio.""" + import datetime as dtm from typing import Optional, Union diff --git a/src/telegram/_files/chatphoto.py b/src/telegram/_files/chatphoto.py index 5d6e91471d7..4716020e44a 100644 --- a/src/telegram/_files/chatphoto.py +++ b/src/telegram/_files/chatphoto.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram ChatPhoto.""" + from typing import TYPE_CHECKING, Final, Optional from telegram import constants diff --git a/src/telegram/_files/contact.py b/src/telegram/_files/contact.py index 1ff05b36dc0..d40de1a1838 100644 --- a/src/telegram/_files/contact.py +++ b/src/telegram/_files/contact.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Contact.""" + from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_files/document.py b/src/telegram/_files/document.py index 7ddaeaf592e..94c40bd07d0 100644 --- a/src/telegram/_files/document.py +++ b/src/telegram/_files/document.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Document.""" + from typing import Optional from telegram._files._basethumbedmedium import _BaseThumbedMedium diff --git a/src/telegram/_files/file.py b/src/telegram/_files/file.py index 38fdac7fd66..eaf8c6b8436 100644 --- a/src/telegram/_files/file.py +++ b/src/telegram/_files/file.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram File.""" + import shutil import urllib.parse as urllib_parse from base64 import b64decode diff --git a/src/telegram/_files/inputmedia.py b/src/telegram/_files/inputmedia.py index 7c831a8246f..6b5c7f50823 100644 --- a/src/telegram/_files/inputmedia.py +++ b/src/telegram/_files/inputmedia.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """Base class for Telegram InputMedia Objects.""" + import datetime as dtm from collections.abc import Sequence from typing import Final, Optional, Union diff --git a/src/telegram/_files/sticker.py b/src/telegram/_files/sticker.py index 0bf63d4b073..eb049f4756f 100644 --- a/src/telegram/_files/sticker.py +++ b/src/telegram/_files/sticker.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains objects that represent stickers.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Final, Optional diff --git a/src/telegram/_files/video.py b/src/telegram/_files/video.py index 7c838d53fc8..c4aaa16853d 100644 --- a/src/telegram/_files/video.py +++ b/src/telegram/_files/video.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Video.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_files/voice.py b/src/telegram/_files/voice.py index d77cdc66aa1..19efbd69c77 100644 --- a/src/telegram/_files/voice.py +++ b/src/telegram/_files/voice.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Voice.""" + import datetime as dtm from typing import Optional, Union diff --git a/src/telegram/_forumtopic.py b/src/telegram/_forumtopic.py index 81b64e28c8e..b9e5436f17c 100644 --- a/src/telegram/_forumtopic.py +++ b/src/telegram/_forumtopic.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains objects related to Telegram forum topics.""" + from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_games/game.py b/src/telegram/_games/game.py index bd8cf19caea..89bd568299c 100644 --- a/src/telegram/_games/game.py +++ b/src/telegram/_games/game.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Game.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_gifts.py b/src/telegram/_gifts.py index 42ec1c45297..7c49aa1fd1e 100644 --- a/src/telegram/_gifts.py +++ b/src/telegram/_gifts.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/] """This module contains classes related to gifs sent by bots.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_giveaway.py b/src/telegram/_giveaway.py index e41f8472b8f..234b97be432 100644 --- a/src/telegram/_giveaway.py +++ b/src/telegram/_giveaway.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an objects that are related to Telegram giveaways.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional @@ -371,7 +372,7 @@ def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "GiveawayComple data = cls._parse_data(data) # Unfortunately, this needs to be here due to cyclic imports - from telegram._message import ( # noqa: PLC0415 # pylint: disable=import-outside-toplevel + from telegram._message import ( # pylint: disable=import-outside-toplevel # noqa: PLC0415 Message, ) diff --git a/src/telegram/_inline/inlinekeyboardmarkup.py b/src/telegram/_inline/inlinekeyboardmarkup.py index 64fd8b49124..424cef04545 100644 --- a/src/telegram/_inline/inlinekeyboardmarkup.py +++ b/src/telegram/_inline/inlinekeyboardmarkup.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram InlineKeyboardMarkup.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inline/inlinequeryresultaudio.py b/src/telegram/_inline/inlinequeryresultaudio.py index 9fcffd07951..af339048284 100644 --- a/src/telegram/_inline/inlinequeryresultaudio.py +++ b/src/telegram/_inline/inlinequeryresultaudio.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultAudio.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_inline/inlinequeryresultcachedaudio.py b/src/telegram/_inline/inlinequeryresultcachedaudio.py index f1f75a12a6e..ef787b5ad0a 100644 --- a/src/telegram/_inline/inlinequeryresultcachedaudio.py +++ b/src/telegram/_inline/inlinequeryresultcachedaudio.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultCachedAudio.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inline/inlinequeryresultcacheddocument.py b/src/telegram/_inline/inlinequeryresultcacheddocument.py index af2e6ef7989..27f06e29f46 100644 --- a/src/telegram/_inline/inlinequeryresultcacheddocument.py +++ b/src/telegram/_inline/inlinequeryresultcacheddocument.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultCachedDocument.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inline/inlinequeryresultcachedgif.py b/src/telegram/_inline/inlinequeryresultcachedgif.py index f682ec0c7d4..0f47247cb9b 100644 --- a/src/telegram/_inline/inlinequeryresultcachedgif.py +++ b/src/telegram/_inline/inlinequeryresultcachedgif.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultCachedGif.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inline/inlinequeryresultcachedmpeg4gif.py b/src/telegram/_inline/inlinequeryresultcachedmpeg4gif.py index 6dc7e557e92..c85d64c332b 100644 --- a/src/telegram/_inline/inlinequeryresultcachedmpeg4gif.py +++ b/src/telegram/_inline/inlinequeryresultcachedmpeg4gif.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inline/inlinequeryresultcachedphoto.py b/src/telegram/_inline/inlinequeryresultcachedphoto.py index adf8ea6b6b4..16c7caca7ab 100644 --- a/src/telegram/_inline/inlinequeryresultcachedphoto.py +++ b/src/telegram/_inline/inlinequeryresultcachedphoto.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultPhoto""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inline/inlinequeryresultcachedvideo.py b/src/telegram/_inline/inlinequeryresultcachedvideo.py index 3595330361a..d6ceb12bbb5 100644 --- a/src/telegram/_inline/inlinequeryresultcachedvideo.py +++ b/src/telegram/_inline/inlinequeryresultcachedvideo.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultCachedVideo.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inline/inlinequeryresultcachedvoice.py b/src/telegram/_inline/inlinequeryresultcachedvoice.py index 139fdabff18..e59563f4789 100644 --- a/src/telegram/_inline/inlinequeryresultcachedvoice.py +++ b/src/telegram/_inline/inlinequeryresultcachedvoice.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultCachedVoice.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inline/inlinequeryresultdocument.py b/src/telegram/_inline/inlinequeryresultdocument.py index e7114ef60aa..5a13e7f7e3f 100644 --- a/src/telegram/_inline/inlinequeryresultdocument.py +++ b/src/telegram/_inline/inlinequeryresultdocument.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultDocument""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inline/inlinequeryresultgame.py b/src/telegram/_inline/inlinequeryresultgame.py index 27b12c87915..525c4f976e9 100644 --- a/src/telegram/_inline/inlinequeryresultgame.py +++ b/src/telegram/_inline/inlinequeryresultgame.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultGame.""" + from typing import Optional from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup diff --git a/src/telegram/_inline/inlinequeryresultgif.py b/src/telegram/_inline/inlinequeryresultgif.py index cbd1f2514b0..6832f6586bc 100644 --- a/src/telegram/_inline/inlinequeryresultgif.py +++ b/src/telegram/_inline/inlinequeryresultgif.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultGif.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_inline/inlinequeryresultmpeg4gif.py b/src/telegram/_inline/inlinequeryresultmpeg4gif.py index 9ca96e12b8e..39940797ec3 100644 --- a/src/telegram/_inline/inlinequeryresultmpeg4gif.py +++ b/src/telegram/_inline/inlinequeryresultmpeg4gif.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_inline/inlinequeryresultphoto.py b/src/telegram/_inline/inlinequeryresultphoto.py index e4556d62d49..b5c5bfb1654 100644 --- a/src/telegram/_inline/inlinequeryresultphoto.py +++ b/src/telegram/_inline/inlinequeryresultphoto.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultPhoto.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inline/inlinequeryresultvideo.py b/src/telegram/_inline/inlinequeryresultvideo.py index 1764816b8a6..8da3e82af86 100644 --- a/src/telegram/_inline/inlinequeryresultvideo.py +++ b/src/telegram/_inline/inlinequeryresultvideo.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultVideo.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_inline/inlinequeryresultvoice.py b/src/telegram/_inline/inlinequeryresultvoice.py index 6f9ef6cee1d..013280255c1 100644 --- a/src/telegram/_inline/inlinequeryresultvoice.py +++ b/src/telegram/_inline/inlinequeryresultvoice.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InlineQueryResultVoice.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_inline/inputcontactmessagecontent.py b/src/telegram/_inline/inputcontactmessagecontent.py index f7a76dff823..008f67474bc 100644 --- a/src/telegram/_inline/inputcontactmessagecontent.py +++ b/src/telegram/_inline/inputcontactmessagecontent.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InputContactMessageContent.""" + from typing import Optional from telegram._inline.inputmessagecontent import InputMessageContent diff --git a/src/telegram/_inline/inputinvoicemessagecontent.py b/src/telegram/_inline/inputinvoicemessagecontent.py index ad486b50cd7..d04be030572 100644 --- a/src/telegram/_inline/inputinvoicemessagecontent.py +++ b/src/telegram/_inline/inputinvoicemessagecontent.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains a class that represents a Telegram InputInvoiceMessageContent.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inline/inputtextmessagecontent.py b/src/telegram/_inline/inputtextmessagecontent.py index 11a2373bb88..d4b17044702 100644 --- a/src/telegram/_inline/inputtextmessagecontent.py +++ b/src/telegram/_inline/inputtextmessagecontent.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InputTextMessageContent.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inline/inputvenuemessagecontent.py b/src/telegram/_inline/inputvenuemessagecontent.py index c836ea11e11..a273d5a9b7a 100644 --- a/src/telegram/_inline/inputvenuemessagecontent.py +++ b/src/telegram/_inline/inputvenuemessagecontent.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram InputVenueMessageContent.""" + from typing import Optional from telegram._inline.inputmessagecontent import InputMessageContent diff --git a/src/telegram/_inline/preparedinlinemessage.py b/src/telegram/_inline/preparedinlinemessage.py index ec2f49b5660..495b50e4be8 100644 --- a/src/telegram/_inline/preparedinlinemessage.py +++ b/src/telegram/_inline/preparedinlinemessage.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Prepared inline Message.""" + import datetime as dtm from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_inputchecklist.py b/src/telegram/_inputchecklist.py index 5b8e8eea019..72a271382cd 100644 --- a/src/telegram/_inputchecklist.py +++ b/src/telegram/_inputchecklist.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an objects that are related to Telegram input checklists.""" + from collections.abc import Sequence from typing import Optional diff --git a/src/telegram/_keyboardbuttonpolltype.py b/src/telegram/_keyboardbuttonpolltype.py index fb21cfe0c5f..3c671e3714b 100644 --- a/src/telegram/_keyboardbuttonpolltype.py +++ b/src/telegram/_keyboardbuttonpolltype.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a type of a Telegram Poll.""" + from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_linkpreviewoptions.py b/src/telegram/_linkpreviewoptions.py index 6e28c92fbf3..d78d9acab74 100644 --- a/src/telegram/_linkpreviewoptions.py +++ b/src/telegram/_linkpreviewoptions.py @@ -18,7 +18,6 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the LinkPreviewOptions class.""" - from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_loginurl.py b/src/telegram/_loginurl.py index 340054268f2..1bc6553d83e 100644 --- a/src/telegram/_loginurl.py +++ b/src/telegram/_loginurl.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram LoginUrl.""" + from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_menubutton.py b/src/telegram/_menubutton.py index fb59a561d25..99658001c10 100644 --- a/src/telegram/_menubutton.py +++ b/src/telegram/_menubutton.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains objects related to Telegram menu buttons.""" + from typing import TYPE_CHECKING, Final, Optional from telegram import constants diff --git a/src/telegram/_messageorigin.py b/src/telegram/_messageorigin.py index 9838d6bea7c..927bd9ba49a 100644 --- a/src/telegram/_messageorigin.py +++ b/src/telegram/_messageorigin.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes that represent Telegram MessageOigin.""" + import datetime as dtm from typing import TYPE_CHECKING, Final, Optional diff --git a/src/telegram/_messagereactionupdated.py b/src/telegram/_messagereactionupdated.py index b1b33851454..88611215472 100644 --- a/src/telegram/_messagereactionupdated.py +++ b/src/telegram/_messagereactionupdated.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram MessageReaction Update.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_paidmessagepricechanged.py b/src/telegram/_paidmessagepricechanged.py index d77cb6d54b0..897bd86ab50 100644 --- a/src/telegram/_paidmessagepricechanged.py +++ b/src/telegram/_paidmessagepricechanged.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that describes a price change of a paid message.""" + from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_passport/encryptedpassportelement.py b/src/telegram/_passport/encryptedpassportelement.py index 65f88e7a69b..1f3c55bd802 100644 --- a/src/telegram/_passport/encryptedpassportelement.py +++ b/src/telegram/_passport/encryptedpassportelement.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram EncryptedPassportElement.""" + from base64 import b64decode from collections.abc import Sequence from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_passport/passportdata.py b/src/telegram/_passport/passportdata.py index fff227a04b6..d05a8778334 100644 --- a/src/telegram/_passport/passportdata.py +++ b/src/telegram/_passport/passportdata.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """Contains information about Telegram Passport data shared with the bot by the user.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_payment/shippingoption.py b/src/telegram/_payment/shippingoption.py index 341dbbe6c51..0054194570b 100644 --- a/src/telegram/_payment/shippingoption.py +++ b/src/telegram/_payment/shippingoption.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram ShippingOption.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_payment/stars/affiliateinfo.py b/src/telegram/_payment/stars/affiliateinfo.py index 64fd7224e23..3d29eb30c7e 100644 --- a/src/telegram/_payment/stars/affiliateinfo.py +++ b/src/telegram/_payment/stars/affiliateinfo.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes for Telegram Stars affiliates.""" + from typing import TYPE_CHECKING, Optional from telegram._chat import Chat diff --git a/src/telegram/_payment/stars/revenuewithdrawalstate.py b/src/telegram/_payment/stars/revenuewithdrawalstate.py index db4f2527706..b83e43d6d04 100644 --- a/src/telegram/_payment/stars/revenuewithdrawalstate.py +++ b/src/telegram/_payment/stars/revenuewithdrawalstate.py @@ -18,6 +18,7 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. # pylint: disable=redefined-builtin """This module contains the classes for Telegram Stars Revenue Withdrawals.""" + import datetime as dtm from typing import TYPE_CHECKING, Final, Optional diff --git a/src/telegram/_payment/stars/staramount.py b/src/telegram/_payment/stars/staramount.py index c78a4aa9aba..026a1950ffd 100644 --- a/src/telegram/_payment/stars/staramount.py +++ b/src/telegram/_payment/stars/staramount.py @@ -18,7 +18,6 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram StarAmount.""" - from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_payment/stars/transactionpartner.py b/src/telegram/_payment/stars/transactionpartner.py index a6d3d9d4979..a27f184b6fc 100644 --- a/src/telegram/_payment/stars/transactionpartner.py +++ b/src/telegram/_payment/stars/transactionpartner.py @@ -18,6 +18,7 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. # pylint: disable=redefined-builtin """This module contains the classes for Telegram Stars transaction partners.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Final, Optional diff --git a/src/telegram/_poll.py b/src/telegram/_poll.py index d8c63389cfd..599f4a65c86 100644 --- a/src/telegram/_poll.py +++ b/src/telegram/_poll.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Poll.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Final, Optional, Union diff --git a/src/telegram/_proximityalerttriggered.py b/src/telegram/_proximityalerttriggered.py index c9e00ef1bf0..72762a61ed1 100644 --- a/src/telegram/_proximityalerttriggered.py +++ b/src/telegram/_proximityalerttriggered.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Proximity Alert.""" + from typing import TYPE_CHECKING, Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_reply.py b/src/telegram/_reply.py index 2887937afe2..ae2165bd60e 100644 --- a/src/telegram/_reply.py +++ b/src/telegram/_reply.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This modules contains objects that represents Telegram Replies""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_replykeyboardremove.py b/src/telegram/_replykeyboardremove.py index 808bee20b6b..9995f1e090d 100644 --- a/src/telegram/_replykeyboardremove.py +++ b/src/telegram/_replykeyboardremove.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram ReplyKeyboardRemove.""" + from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_sentwebappmessage.py b/src/telegram/_sentwebappmessage.py index 492f440d003..3fdd22a920f 100644 --- a/src/telegram/_sentwebappmessage.py +++ b/src/telegram/_sentwebappmessage.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Sent Web App Message.""" + from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_shared.py b/src/telegram/_shared.py index 8c8b1490101..7d403508f99 100644 --- a/src/telegram/_shared.py +++ b/src/telegram/_shared.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains two objects used for request chats/users service messages.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_switchinlinequerychosenchat.py b/src/telegram/_switchinlinequerychosenchat.py index 7fca5a9f728..9e05cf42224 100644 --- a/src/telegram/_switchinlinequerychosenchat.py +++ b/src/telegram/_switchinlinequerychosenchat.py @@ -16,6 +16,7 @@ # # You should have received a copy of the GNU Lesser Public License """This module contains a class that represents a Telegram SwitchInlineQueryChosenChat.""" + from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/_telegramobject.py b/src/telegram/_telegramobject.py index 70968826bb7..880474329db 100644 --- a/src/telegram/_telegramobject.py +++ b/src/telegram/_telegramobject.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """Base class for Telegram Objects.""" + import contextlib import datetime as dtm import inspect @@ -206,8 +207,7 @@ def __repr__(self) -> str: if ( as_dict[k] is not None and not ( - isinstance(as_dict[k], Sized) - and len(as_dict[k]) == 0 # type: ignore[arg-type] + isinstance(as_dict[k], Sized) and len(as_dict[k]) == 0 # type: ignore[arg-type] ) ) ) diff --git a/src/telegram/_uniquegift.py b/src/telegram/_uniquegift.py index 31d47372fe8..264b1ede4e1 100644 --- a/src/telegram/_uniquegift.py +++ b/src/telegram/_uniquegift.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/] """This module contains classes related to unique gifs.""" + import datetime as dtm from typing import TYPE_CHECKING, Final, Optional diff --git a/src/telegram/_user.py b/src/telegram/_user.py index 43a80a65275..ca9cd637193 100644 --- a/src/telegram/_user.py +++ b/src/telegram/_user.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram User.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_userprofilephotos.py b/src/telegram/_userprofilephotos.py index 95344c1be5f..f138f062a4b 100644 --- a/src/telegram/_userprofilephotos.py +++ b/src/telegram/_userprofilephotos.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram UserProfilePhotos.""" + from collections.abc import Sequence from typing import TYPE_CHECKING, Optional diff --git a/src/telegram/_utils/argumentparsing.py b/src/telegram/_utils/argumentparsing.py index acebbf06440..8c470812c81 100644 --- a/src/telegram/_utils/argumentparsing.py +++ b/src/telegram/_utils/argumentparsing.py @@ -23,6 +23,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional, Protocol, TypeVar, Union, overload diff --git a/src/telegram/_utils/datetime.py b/src/telegram/_utils/datetime.py index a0cc126dd94..0d67b132102 100644 --- a/src/telegram/_utils/datetime.py +++ b/src/telegram/_utils/datetime.py @@ -27,6 +27,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + import contextlib import datetime as dtm import os @@ -268,7 +269,5 @@ def get_timedelta_value( stacklevel=2, ) return ( - int(seconds) - if (seconds := value.total_seconds()).is_integer() - else seconds # type: ignore[return-value] + int(seconds) if (seconds := value.total_seconds()).is_integer() else seconds # type: ignore[return-value] # pylint: disable=line-too-long ) diff --git a/src/telegram/_utils/defaultvalue.py b/src/telegram/_utils/defaultvalue.py index f9374c54af7..44b5d2b3ffe 100644 --- a/src/telegram/_utils/defaultvalue.py +++ b/src/telegram/_utils/defaultvalue.py @@ -27,6 +27,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + from typing import Generic, TypeVar, Union, overload DVType = TypeVar("DVType", bound=object) # pylint: disable=invalid-name diff --git a/src/telegram/_utils/entities.py b/src/telegram/_utils/entities.py index 7ca3eff20fb..1201dcd485e 100644 --- a/src/telegram/_utils/entities.py +++ b/src/telegram/_utils/entities.py @@ -23,6 +23,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + from collections.abc import Sequence from typing import Optional diff --git a/src/telegram/_utils/enum.py b/src/telegram/_utils/enum.py index 58362870f7e..d7ca5ea245b 100644 --- a/src/telegram/_utils/enum.py +++ b/src/telegram/_utils/enum.py @@ -23,6 +23,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + import enum as _enum import sys from typing import TypeVar, Union diff --git a/src/telegram/_utils/logging.py b/src/telegram/_utils/logging.py index 0bd778b8bd7..511f12ea80b 100644 --- a/src/telegram/_utils/logging.py +++ b/src/telegram/_utils/logging.py @@ -23,6 +23,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + import logging from typing import Optional diff --git a/src/telegram/_utils/markup.py b/src/telegram/_utils/markup.py index eed70b3bacd..256fb679b42 100644 --- a/src/telegram/_utils/markup.py +++ b/src/telegram/_utils/markup.py @@ -27,6 +27,7 @@ class ``telegram.ReplyMarkup``. user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + from collections.abc import Sequence diff --git a/src/telegram/_utils/repr.py b/src/telegram/_utils/repr.py index 38d9834e3bb..7e889c27bf6 100644 --- a/src/telegram/_utils/repr.py +++ b/src/telegram/_utils/repr.py @@ -23,6 +23,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + from typing import Any diff --git a/src/telegram/_utils/types.py b/src/telegram/_utils/types.py index 925fba94cad..bbed0ae3228 100644 --- a/src/telegram/_utils/types.py +++ b/src/telegram/_utils/types.py @@ -23,6 +23,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + import datetime as dtm from collections.abc import Collection from pathlib import Path diff --git a/src/telegram/_utils/usernames.py b/src/telegram/_utils/usernames.py index 40ed7d80549..26f3450bcd0 100644 --- a/src/telegram/_utils/usernames.py +++ b/src/telegram/_utils/usernames.py @@ -24,6 +24,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + from typing import TYPE_CHECKING, Optional, Protocol, TypeVar, Union, overload TeleUserLike = TypeVar("TeleUserLike", bound="UserLike") diff --git a/src/telegram/_utils/warnings.py b/src/telegram/_utils/warnings.py index 2aa79db58d1..a7055fef682 100644 --- a/src/telegram/_utils/warnings.py +++ b/src/telegram/_utils/warnings.py @@ -25,6 +25,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + import warnings from typing import Union diff --git a/src/telegram/_utils/warnings_transition.py b/src/telegram/_utils/warnings_transition.py index 7aca62c2ac6..a478d056eee 100644 --- a/src/telegram/_utils/warnings_transition.py +++ b/src/telegram/_utils/warnings_transition.py @@ -23,6 +23,7 @@ .. versionadded:: 20.2 """ + from typing import Any, Callable, Union from telegram._utils.warnings import warn diff --git a/src/telegram/_videochat.py b/src/telegram/_videochat.py index 97f51501da4..486fa93269c 100644 --- a/src/telegram/_videochat.py +++ b/src/telegram/_videochat.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains objects related to Telegram video chats.""" + import datetime as dtm from collections.abc import Sequence from typing import TYPE_CHECKING, Optional, Union diff --git a/src/telegram/_writeaccessallowed.py b/src/telegram/_writeaccessallowed.py index 07fdd6ba7e4..7671ceacdac 100644 --- a/src/telegram/_writeaccessallowed.py +++ b/src/telegram/_writeaccessallowed.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains objects related to the write access allowed service message.""" + from typing import Optional from telegram._telegramobject import TelegramObject diff --git a/src/telegram/ext/_aioratelimiter.py b/src/telegram/ext/_aioratelimiter.py index d2d537e7e27..0e2f3f3f305 100644 --- a/src/telegram/ext/_aioratelimiter.py +++ b/src/telegram/ext/_aioratelimiter.py @@ -19,6 +19,7 @@ """This module contains an implementation of the BaseRateLimiter class based on the aiolimiter library. """ + import asyncio import contextlib import sys diff --git a/src/telegram/ext/_application.py b/src/telegram/ext/_application.py index 51f739b3e27..3e5c5401d4f 100644 --- a/src/telegram/ext/_application.py +++ b/src/telegram/ext/_application.py @@ -455,7 +455,7 @@ def builder() -> "InitApplicationBuilder": .. versionadded:: 20.0 """ # Unfortunately this needs to be here due to cyclical imports - from telegram.ext import ( # noqa: PLC0415 # pylint: disable=import-outside-toplevel + from telegram.ext import ( # pylint: disable=import-outside-toplevel # noqa: PLC0415 ApplicationBuilder, ) @@ -1302,8 +1302,7 @@ async def process_update(self, update: object) -> None: coroutine, update=update, name=( - f"Application:{self.bot.id}:process_update_non_blocking" - f":{handler}" + f"Application:{self.bot.id}:process_update_non_blocking:{handler}" ), ) else: diff --git a/src/telegram/ext/_applicationbuilder.py b/src/telegram/ext/_applicationbuilder.py index 0b258584ab5..aac0084bea7 100644 --- a/src/telegram/ext/_applicationbuilder.py +++ b/src/telegram/ext/_applicationbuilder.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the Builder classes for the telegram.ext module.""" + from asyncio import Queue from collections.abc import Collection, Coroutine from pathlib import Path diff --git a/src/telegram/ext/_basepersistence.py b/src/telegram/ext/_basepersistence.py index 3571f6d961b..2bdd6b808d9 100644 --- a/src/telegram/ext/_basepersistence.py +++ b/src/telegram/ext/_basepersistence.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the BasePersistence class.""" + from abc import ABC, abstractmethod from typing import Generic, NamedTuple, NoReturn, Optional diff --git a/src/telegram/ext/_baseratelimiter.py b/src/telegram/ext/_baseratelimiter.py index ad11e444ac8..6de2569dde4 100644 --- a/src/telegram/ext/_baseratelimiter.py +++ b/src/telegram/ext/_baseratelimiter.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains a class that allows to rate limit requests to the Bot API.""" + from abc import ABC, abstractmethod from collections.abc import Coroutine from typing import Any, Callable, Generic, Optional, Union diff --git a/src/telegram/ext/_baseupdateprocessor.py b/src/telegram/ext/_baseupdateprocessor.py index c08afec0b41..4b9a79559ff 100644 --- a/src/telegram/ext/_baseupdateprocessor.py +++ b/src/telegram/ext/_baseupdateprocessor.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the BaseProcessor class.""" + from abc import ABC, abstractmethod from contextlib import AbstractAsyncContextManager from types import TracebackType diff --git a/src/telegram/ext/_callbackdatacache.py b/src/telegram/ext/_callbackdatacache.py index a24befd719d..10c0454ad00 100644 --- a/src/telegram/ext/_callbackdatacache.py +++ b/src/telegram/ext/_callbackdatacache.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the CallbackDataCache class.""" + import datetime as dtm import time from collections.abc import MutableMapping diff --git a/src/telegram/ext/_contexttypes.py b/src/telegram/ext/_contexttypes.py index 2d3a8b357e8..10c8e937e05 100644 --- a/src/telegram/ext/_contexttypes.py +++ b/src/telegram/ext/_contexttypes.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the auxiliary class ContextTypes.""" + from typing import Any, Generic, overload from telegram.ext._callbackcontext import CallbackContext diff --git a/src/telegram/ext/_defaults.py b/src/telegram/ext/_defaults.py index d7134766695..edfe206254c 100644 --- a/src/telegram/ext/_defaults.py +++ b/src/telegram/ext/_defaults.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the class Defaults, which allows passing default values to Application.""" + import datetime as dtm from typing import TYPE_CHECKING, Any, NoReturn, Optional, final diff --git a/src/telegram/ext/_dictpersistence.py b/src/telegram/ext/_dictpersistence.py index 758a8dd5436..21bba7e8694 100644 --- a/src/telegram/ext/_dictpersistence.py +++ b/src/telegram/ext/_dictpersistence.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the DictPersistence class.""" + import json from copy import deepcopy from typing import TYPE_CHECKING, Any, Optional, cast diff --git a/src/telegram/ext/_extbot.py b/src/telegram/ext/_extbot.py index 3c956594632..1f9e14644c9 100644 --- a/src/telegram/ext/_extbot.py +++ b/src/telegram/ext/_extbot.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an object that represents a Telegram Bot with convenience extensions.""" + import datetime as dtm from collections.abc import Sequence from copy import copy diff --git a/src/telegram/ext/_handlers/basehandler.py b/src/telegram/ext/_handlers/basehandler.py index b6353f214cf..fc60b0884b4 100644 --- a/src/telegram/ext/_handlers/basehandler.py +++ b/src/telegram/ext/_handlers/basehandler.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the base class for handlers as used by the Application.""" + from abc import ABC, abstractmethod from typing import TYPE_CHECKING, Any, Generic, Optional, TypeVar, Union diff --git a/src/telegram/ext/_handlers/businessconnectionhandler.py b/src/telegram/ext/_handlers/businessconnectionhandler.py index 975bb475474..0123cf49985 100644 --- a/src/telegram/ext/_handlers/businessconnectionhandler.py +++ b/src/telegram/ext/_handlers/businessconnectionhandler.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the BusinessConnectionHandler class.""" + from typing import Optional, TypeVar from telegram import Update diff --git a/src/telegram/ext/_handlers/businessmessagesdeletedhandler.py b/src/telegram/ext/_handlers/businessmessagesdeletedhandler.py index c2df450f30e..a9261466237 100644 --- a/src/telegram/ext/_handlers/businessmessagesdeletedhandler.py +++ b/src/telegram/ext/_handlers/businessmessagesdeletedhandler.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the BusinessMessagesDeletedHandler class.""" + from typing import Optional, TypeVar from telegram import Update diff --git a/src/telegram/ext/_handlers/callbackqueryhandler.py b/src/telegram/ext/_handlers/callbackqueryhandler.py index 27ddc5b2ec4..f4ed15e6c7d 100644 --- a/src/telegram/ext/_handlers/callbackqueryhandler.py +++ b/src/telegram/ext/_handlers/callbackqueryhandler.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the CallbackQueryHandler class.""" + import asyncio import re from re import Match, Pattern diff --git a/src/telegram/ext/_handlers/chatmemberhandler.py b/src/telegram/ext/_handlers/chatmemberhandler.py index a2b281c854b..1f14ecde877 100644 --- a/src/telegram/ext/_handlers/chatmemberhandler.py +++ b/src/telegram/ext/_handlers/chatmemberhandler.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the ChatMemberHandler class.""" + from typing import Final, Optional, TypeVar from telegram import Update diff --git a/src/telegram/ext/_handlers/choseninlineresulthandler.py b/src/telegram/ext/_handlers/choseninlineresulthandler.py index 2faa0bc862c..ae3d1996d6b 100644 --- a/src/telegram/ext/_handlers/choseninlineresulthandler.py +++ b/src/telegram/ext/_handlers/choseninlineresulthandler.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the ChosenInlineResultHandler class.""" + import re from re import Match, Pattern from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union, cast diff --git a/src/telegram/ext/_handlers/commandhandler.py b/src/telegram/ext/_handlers/commandhandler.py index 27f7a42cd49..c23e3384480 100644 --- a/src/telegram/ext/_handlers/commandhandler.py +++ b/src/telegram/ext/_handlers/commandhandler.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the CommandHandler class.""" + import re from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union diff --git a/src/telegram/ext/_handlers/conversationhandler.py b/src/telegram/ext/_handlers/conversationhandler.py index d0a3734d61b..e17bd4ae86e 100644 --- a/src/telegram/ext/_handlers/conversationhandler.py +++ b/src/telegram/ext/_handlers/conversationhandler.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the ConversationHandler.""" + import asyncio import datetime as dtm from dataclasses import dataclass diff --git a/src/telegram/ext/_handlers/inlinequeryhandler.py b/src/telegram/ext/_handlers/inlinequeryhandler.py index 3e7b7c4d400..14422291175 100644 --- a/src/telegram/ext/_handlers/inlinequeryhandler.py +++ b/src/telegram/ext/_handlers/inlinequeryhandler.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the InlineQueryHandler class.""" + import re from re import Match, Pattern from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union, cast diff --git a/src/telegram/ext/_handlers/messagehandler.py b/src/telegram/ext/_handlers/messagehandler.py index 625531a565e..9b6abeef534 100644 --- a/src/telegram/ext/_handlers/messagehandler.py +++ b/src/telegram/ext/_handlers/messagehandler.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the MessageHandler class.""" + from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union from telegram import Update diff --git a/src/telegram/ext/_handlers/pollanswerhandler.py b/src/telegram/ext/_handlers/pollanswerhandler.py index 69f189361ca..8d3d7dfb0f1 100644 --- a/src/telegram/ext/_handlers/pollanswerhandler.py +++ b/src/telegram/ext/_handlers/pollanswerhandler.py @@ -18,7 +18,6 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the PollAnswerHandler class.""" - from telegram import Update from telegram.ext._handlers.basehandler import BaseHandler from telegram.ext._utils.types import CCT, RT diff --git a/src/telegram/ext/_handlers/pollhandler.py b/src/telegram/ext/_handlers/pollhandler.py index 36fc9bc0066..57fafef8a97 100644 --- a/src/telegram/ext/_handlers/pollhandler.py +++ b/src/telegram/ext/_handlers/pollhandler.py @@ -18,7 +18,6 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the PollHandler class.""" - from telegram import Update from telegram.ext._handlers.basehandler import BaseHandler from telegram.ext._utils.types import CCT, RT diff --git a/src/telegram/ext/_handlers/precheckoutqueryhandler.py b/src/telegram/ext/_handlers/precheckoutqueryhandler.py index 04bf395bffb..f61dd35266c 100644 --- a/src/telegram/ext/_handlers/precheckoutqueryhandler.py +++ b/src/telegram/ext/_handlers/precheckoutqueryhandler.py @@ -18,7 +18,6 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the PreCheckoutQueryHandler class.""" - import re from re import Pattern from typing import Optional, TypeVar, Union diff --git a/src/telegram/ext/_handlers/prefixhandler.py b/src/telegram/ext/_handlers/prefixhandler.py index a6e4f38c2ad..65ae4152856 100644 --- a/src/telegram/ext/_handlers/prefixhandler.py +++ b/src/telegram/ext/_handlers/prefixhandler.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the PrefixHandler class.""" + import itertools from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union diff --git a/src/telegram/ext/_handlers/shippingqueryhandler.py b/src/telegram/ext/_handlers/shippingqueryhandler.py index 1795a93ff80..bc15b6876e7 100644 --- a/src/telegram/ext/_handlers/shippingqueryhandler.py +++ b/src/telegram/ext/_handlers/shippingqueryhandler.py @@ -18,7 +18,6 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the ShippingQueryHandler class.""" - from telegram import Update from telegram.ext._handlers.basehandler import BaseHandler from telegram.ext._utils.types import CCT, RT diff --git a/src/telegram/ext/_jobqueue.py b/src/telegram/ext/_jobqueue.py index 70c640544c3..8c2baae61c8 100644 --- a/src/telegram/ext/_jobqueue.py +++ b/src/telegram/ext/_jobqueue.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the classes JobQueue and Job.""" + import asyncio import datetime as dtm import re diff --git a/src/telegram/ext/_picklepersistence.py b/src/telegram/ext/_picklepersistence.py index 1602eabed0e..4c371ffbb8f 100644 --- a/src/telegram/ext/_picklepersistence.py +++ b/src/telegram/ext/_picklepersistence.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the PicklePersistence class.""" + import pickle from copy import deepcopy from pathlib import Path diff --git a/src/telegram/ext/_utils/_update_parsing.py b/src/telegram/ext/_utils/_update_parsing.py index 2d62a6b05f9..dc5ff73940b 100644 --- a/src/telegram/ext/_utils/_update_parsing.py +++ b/src/telegram/ext/_utils/_update_parsing.py @@ -25,6 +25,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + from typing import Optional from telegram._utils.types import SCT diff --git a/src/telegram/ext/_utils/asyncio.py b/src/telegram/ext/_utils/asyncio.py index 722c1c3662c..2efaedb0671 100644 --- a/src/telegram/ext/_utils/asyncio.py +++ b/src/telegram/ext/_utils/asyncio.py @@ -25,6 +25,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + import asyncio from typing import Literal diff --git a/src/telegram/ext/_utils/networkloop.py b/src/telegram/ext/_utils/networkloop.py index 2cc93113272..41de1b44c0a 100644 --- a/src/telegram/ext/_utils/networkloop.py +++ b/src/telegram/ext/_utils/networkloop.py @@ -30,6 +30,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + import asyncio import contextlib from collections.abc import Coroutine diff --git a/src/telegram/ext/_utils/stack.py b/src/telegram/ext/_utils/stack.py index e4eef2ba92f..dcb91b64532 100644 --- a/src/telegram/ext/_utils/stack.py +++ b/src/telegram/ext/_utils/stack.py @@ -25,6 +25,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + from pathlib import Path from types import FrameType from typing import Optional diff --git a/src/telegram/ext/_utils/trackingdict.py b/src/telegram/ext/_utils/trackingdict.py index 810ecc6df49..4b42c7f19d9 100644 --- a/src/telegram/ext/_utils/trackingdict.py +++ b/src/telegram/ext/_utils/trackingdict.py @@ -25,6 +25,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + from collections import UserDict from collections.abc import Mapping from typing import Final, Generic, Optional, TypeVar, Union diff --git a/src/telegram/ext/_utils/types.py b/src/telegram/ext/_utils/types.py index 6aa35c89e22..af1059dc0cf 100644 --- a/src/telegram/ext/_utils/types.py +++ b/src/telegram/ext/_utils/types.py @@ -25,6 +25,7 @@ user. Changes to this module are not considered breaking changes and may not be documented in the changelog. """ + from collections.abc import Coroutine, MutableMapping from typing import TYPE_CHECKING, Any, Callable, TypeVar, Union diff --git a/src/telegram/request/_baserequest.py b/src/telegram/request/_baserequest.py index 879d79d1ce2..cdd4af88c91 100644 --- a/src/telegram/request/_baserequest.py +++ b/src/telegram/request/_baserequest.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains an abstract class to make POST and GET requests.""" + import abc import json from contextlib import AbstractAsyncContextManager diff --git a/src/telegram/request/_httpxrequest.py b/src/telegram/request/_httpxrequest.py index bb35501f178..5b1b412463e 100644 --- a/src/telegram/request/_httpxrequest.py +++ b/src/telegram/request/_httpxrequest.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains methods to make POST and GET requests using the httpx library.""" + from collections.abc import Collection from typing import Any, Optional, Union diff --git a/src/telegram/request/_requestdata.py b/src/telegram/request/_requestdata.py index b8da33cc07b..87148c1e046 100644 --- a/src/telegram/request/_requestdata.py +++ b/src/telegram/request/_requestdata.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains a class that holds the parameters of a request to the Bot API.""" + import json from typing import Any, Optional, Union, final from urllib.parse import urlencode diff --git a/src/telegram/request/_requestparameter.py b/src/telegram/request/_requestparameter.py index f0664c7943d..363808f0186 100644 --- a/src/telegram/request/_requestparameter.py +++ b/src/telegram/request/_requestparameter.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains a class that describes a single parameter of a request to the Bot API.""" + import datetime as dtm import json from collections.abc import Sequence diff --git a/tests/_files/conftest.py b/tests/_files/conftest.py index eeb59e888c1..c552a35151f 100644 --- a/tests/_files/conftest.py +++ b/tests/_files/conftest.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """Module to provide fixtures most of which are used in test_inputmedia.py.""" + import pytest from telegram.error import BadRequest diff --git a/tests/_files/test_inputprofilephoto.py b/tests/_files/test_inputprofilephoto.py index 363bf5a9fd2..1d0fb56b02b 100644 --- a/tests/_files/test_inputprofilephoto.py +++ b/tests/_files/test_inputprofilephoto.py @@ -32,7 +32,6 @@ class TestInputProfilePhotoWithoutRequest: - def test_type_enum_conversion(self): instance = InputProfilePhoto(type="static") assert isinstance(instance.type, InputProfilePhotoType) diff --git a/tests/_files/test_inputstorycontent.py b/tests/_files/test_inputstorycontent.py index 37762a24e1a..7eb73b561fe 100644 --- a/tests/_files/test_inputstorycontent.py +++ b/tests/_files/test_inputstorycontent.py @@ -61,7 +61,6 @@ class InputStoryContentPhotoTestBase: class TestInputStoryContentPhotoWithoutRequest(InputStoryContentPhotoTestBase): - def test_slot_behaviour(self, input_story_content_photo): inst = input_story_content_photo for attr in inst.__slots__: diff --git a/tests/_inline/test_inputinvoicemessagecontent.py b/tests/_inline/test_inputinvoicemessagecontent.py index d3d431c6843..f99712bc0d3 100644 --- a/tests/_inline/test_inputinvoicemessagecontent.py +++ b/tests/_inline/test_inputinvoicemessagecontent.py @@ -204,7 +204,6 @@ def test_to_dict(self, input_invoice_message_content): ) def test_de_json(self, offline_bot): - json_dict = { "title": self.title, "description": self.description, diff --git a/tests/_passport/test_no_passport.py b/tests/_passport/test_no_passport.py index 4e861894bf3..ac2a80fe39d 100644 --- a/tests/_passport/test_no_passport.py +++ b/tests/_passport/test_no_passport.py @@ -26,6 +26,7 @@ with the TEST_WITH_OPT_DEPS environment variable set to False in addition to the regular test suite """ + import pytest import telegram diff --git a/tests/_utils/test_datetime.py b/tests/_utils/test_datetime.py index 06d252a64a2..d32256d566f 100644 --- a/tests/_utils/test_datetime.py +++ b/tests/_utils/test_datetime.py @@ -118,9 +118,9 @@ def test_to_float_timestamp_delta(self): reference_t = 0 for i in DELTA_TIME_SPECS: delta = i.total_seconds() if hasattr(i, "total_seconds") else i - assert ( - tg_dtm.to_float_timestamp(i, reference_t) == reference_t + delta - ), f"failed for {i}" + assert tg_dtm.to_float_timestamp(i, reference_t) == reference_t + delta, ( + f"failed for {i}" + ) def test_to_float_timestamp_time_of_day(self): """Conversion from time-of-day specification to timestamp""" diff --git a/tests/auxil/bot_method_checks.py b/tests/auxil/bot_method_checks.py index 508fa3d9aa7..5ff6b3695ee 100644 --- a/tests/auxil/bot_method_checks.py +++ b/tests/auxil/bot_method_checks.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """Provides functions to test both methods.""" + import datetime as dtm import functools import inspect diff --git a/tests/auxil/ci_bots.py b/tests/auxil/ci_bots.py index cb05004a0d0..176adba01ff 100644 --- a/tests/auxil/ci_bots.py +++ b/tests/auxil/ci_bots.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """Provide a bot to tests""" + import base64 import json import os @@ -49,9 +50,7 @@ BOTS = json.loads(base64.b64decode(BOTS).decode(TextEncoding.UTF_8)) JOB_INDEX = int(JOB_INDEX) -FALLBACKS = json.loads( - base64.b64decode(FALLBACKS).decode(TextEncoding.UTF_8) -) # type: list[dict[str, str]] +FALLBACKS = json.loads(base64.b64decode(FALLBACKS).decode(TextEncoding.UTF_8)) # type: list[dict[str, str]] class BotInfoProvider: diff --git a/tests/auxil/pytest_classes.py b/tests/auxil/pytest_classes.py index c3694a8f0aa..e2501605c9a 100644 --- a/tests/auxil/pytest_classes.py +++ b/tests/auxil/pytest_classes.py @@ -20,6 +20,7 @@ modify behavior of the respective parent classes in order to make them easier to use in the pytest framework. A common change is to allow monkeypatching of the class members by not enforcing slots in the subclasses.""" + from telegram import Bot, Message, User from telegram.ext import Application, ExtBot, Updater from tests.auxil.ci_bots import BOT_INFO_PROVIDER diff --git a/tests/ext/test_application.py b/tests/ext/test_application.py index c99a1311d27..d30d7d845a0 100644 --- a/tests/ext/test_application.py +++ b/tests/ext/test_application.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """The integration of persistence into the application is tested in test_basepersistence.""" + import asyncio import functools import inspect @@ -1005,9 +1006,9 @@ async def callback(update, context): str(recwarn[0].message) == "ApplicationHandlerStop is not supported with handlers running non-blocking." ) - assert ( - Path(recwarn[0].filename) == SOURCE_ROOT_PATH / "ext" / "_application.py" - ), "incorrect stacklevel!" + assert Path(recwarn[0].filename) == SOURCE_ROOT_PATH / "ext" / "_application.py", ( + "incorrect stacklevel!" + ) async def test_non_blocking_no_error_handler(self, app, caplog): app.add_handler(TypeHandler(object, self.callback_raise_error("Test error"), block=False)) @@ -1078,9 +1079,9 @@ async def error_handler(update, context): str(recwarn[0].message) == "ApplicationHandlerStop is not supported with handlers running non-blocking." ) - assert ( - Path(recwarn[0].filename) == SOURCE_ROOT_PATH / "ext" / "_application.py" - ), "incorrect stacklevel!" + assert Path(recwarn[0].filename) == SOURCE_ROOT_PATH / "ext" / "_application.py", ( + "incorrect stacklevel!" + ) @pytest.mark.parametrize(("block", "expected_output"), [(False, 0), (True, 5)]) async def test_default_block_error_handler(self, bot_info, block, expected_output): diff --git a/tests/ext/test_applicationbuilder.py b/tests/ext/test_applicationbuilder.py index bfbce15dd93..847ce178892 100644 --- a/tests/ext/test_applicationbuilder.py +++ b/tests/ext/test_applicationbuilder.py @@ -346,11 +346,7 @@ def test_all_bot_args_custom( PRIVATE_KEY ).defaults(defaults).arbitrary_callback_data(42).request(request).get_updates_request( get_updates_request - ).rate_limiter( - rate_limiter - ).local_mode( - True - ) + ).rate_limiter(rate_limiter).local_mode(True) built_bot = builder.build().bot # In the following we access some private attributes of bot and request. this is not @@ -407,11 +403,7 @@ def init_httpx_request(self_, *args, **kwargs): 2 ).get_updates_pool_timeout(3).get_updates_read_timeout(4).get_updates_write_timeout( 5 - ).get_updates_http_version( - "1.1" - ).get_updates_proxy( - "get_updates_proxy" - ) + ).get_updates_http_version("1.1").get_updates_proxy("get_updates_proxy") app = builder.build() client = app.bot._request[0]._client diff --git a/tests/ext/test_baseupdateprocessor.py b/tests/ext/test_baseupdateprocessor.py index 21cd08f3367..4b65ec375d3 100644 --- a/tests/ext/test_baseupdateprocessor.py +++ b/tests/ext/test_baseupdateprocessor.py @@ -18,6 +18,7 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. """Here we run tests directly with SimpleUpdateProcessor because that's easier than providing dummy implementations for SimpleUpdateProcessor and we want to test SimpleUpdateProcessor anyway.""" + import asyncio import pytest diff --git a/tests/ext/test_callbackdatacache.py b/tests/ext/test_callbackdatacache.py index 084a6b1887e..f0a5f7b6c7a 100644 --- a/tests/ext/test_callbackdatacache.py +++ b/tests/ext/test_callbackdatacache.py @@ -68,9 +68,9 @@ def test_slot_behaviour(self): keyboard_data = _KeyboardData("uuid") for attr in keyboard_data.__slots__: assert getattr(keyboard_data, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(keyboard_data)) == len( - set(mro_slots(keyboard_data)) - ), "duplicate slot" + assert len(mro_slots(keyboard_data)) == len(set(mro_slots(keyboard_data))), ( + "duplicate slot" + ) @pytest.mark.skipif( @@ -86,9 +86,9 @@ def test_slot_behaviour(self, callback_data_cache): else attr ) assert getattr(callback_data_cache, at, "err") != "err", f"got extra slot '{at}'" - assert len(mro_slots(callback_data_cache)) == len( - set(mro_slots(callback_data_cache)) - ), "duplicate slot" + assert len(mro_slots(callback_data_cache)) == len(set(mro_slots(callback_data_cache))), ( + "duplicate slot" + ) @pytest.mark.parametrize("maxsize", [1, 5, 2048]) def test_init_maxsize(self, maxsize, bot): diff --git a/tests/ext/test_conversationhandler.py b/tests/ext/test_conversationhandler.py index 4a5ceb68394..bb451143f8d 100644 --- a/tests/ext/test_conversationhandler.py +++ b/tests/ext/test_conversationhandler.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """Persistence of conversations is tested in test_basepersistence.py""" + import asyncio import functools import logging @@ -1422,9 +1423,9 @@ def timeout(*args, **kwargs): assert len(recwarn) == 1 assert str(recwarn[0].message).startswith("ApplicationHandlerStop in TIMEOUT") assert recwarn[0].category is PTBUserWarning - assert ( - Path(recwarn[0].filename) == SOURCE_ROOT_PATH / "ext" / "_jobqueue.py" - ), "wrong stacklevel!" + assert Path(recwarn[0].filename) == SOURCE_ROOT_PATH / "ext" / "_jobqueue.py", ( + "wrong stacklevel!" + ) await app.stop() diff --git a/tests/ext/test_filters.py b/tests/ext/test_filters.py index 097d6ddf706..48c2cf80d59 100644 --- a/tests/ext/test_filters.py +++ b/tests/ext/test_filters.py @@ -158,9 +158,9 @@ def test__all__(self): ) } actual = set(filters.__all__) - assert ( - actual == expected - ), f"Members {expected - actual} were not listed in constants.__all__" + assert actual == expected, ( + f"Members {expected - actual} were not listed in constants.__all__" + ) def test_filters_all(self, update): assert filters.ALL.check_update(update) diff --git a/tests/ext/test_picklepersistence.py b/tests/ext/test_picklepersistence.py index f5c15c5cb9b..edcce8055e4 100644 --- a/tests/ext/test_picklepersistence.py +++ b/tests/ext/test_picklepersistence.py @@ -898,9 +898,9 @@ async def test_custom_pickler_unpickler_simple( assert len(recwarn) == 1 assert recwarn[-1].category is PTBUserWarning assert str(recwarn[-1].message).startswith("Unknown bot instance found.") - assert ( - Path(recwarn[-1].filename) == SOURCE_ROOT_PATH / "ext" / "_picklepersistence.py" - ), "wrong stacklevel!" + assert Path(recwarn[-1].filename) == SOURCE_ROOT_PATH / "ext" / "_picklepersistence.py", ( + "wrong stacklevel!" + ) pp = PicklePersistence("pickletest", single_file=False, on_flush=False) pp.set_bot(bot) assert (await pp.get_chat_data())[12345]["unknown_bot_in_user"]._bot is None diff --git a/tests/ext/test_ratelimiter.py b/tests/ext/test_ratelimiter.py index c253ee27c8c..4f4e515199f 100644 --- a/tests/ext/test_ratelimiter.py +++ b/tests/ext/test_ratelimiter.py @@ -21,6 +21,7 @@ We mostly test on directly on AIORateLimiter here, b/c BaseRateLimiter doesn't contain anything notable """ + import asyncio import datetime as dtm import json diff --git a/tests/ext/test_updater.py b/tests/ext/test_updater.py index 92a2d65ce7d..ebca2585df9 100644 --- a/tests/ext/test_updater.py +++ b/tests/ext/test_updater.py @@ -374,7 +374,6 @@ async def get_updates(*args, **kwargs): assert log_found async def test_polling_mark_updates_as_read_failure(self, monkeypatch, updater, caplog): - monkeypatch.setattr(updater.bot, "get_updates", empty_get_updates) async with updater: @@ -399,7 +398,6 @@ async def test_polling_mark_updates_as_read_failure(self, monkeypatch, updater, assert log_found async def test_start_polling_already_running(self, updater, monkeypatch): - monkeypatch.setattr(updater.bot, "get_updates", empty_get_updates) async with updater: @@ -956,7 +954,6 @@ async def test_webhook_arbitrary_callback_data( monkeypatch.setattr(updater.bot, "set_webhook", return_true) try: - ip = "127.0.0.1" port = randrange(1024, 49152) # Select random port @@ -998,7 +995,6 @@ async def test_webhook_arbitrary_callback_data( updater.bot.callback_data_cache.clear_callback_queries() async def test_webhook_invalid_ssl(self, monkeypatch, updater): - ip = "127.0.0.1" port = randrange(1024, 49152) # Select random port async with updater: @@ -1070,7 +1066,6 @@ async def set_webhook(*args, **kwargs): ) async def test_webhook_invalid_posts(self, updater, monkeypatch): - ip = "127.0.0.1" port = randrange(1024, 49152) diff --git a/tests/request/test_request.py b/tests/request/test_request.py index 0ebfe73532f..eda6829ccf7 100644 --- a/tests/request/test_request.py +++ b/tests/request/test_request.py @@ -18,6 +18,7 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. """Here we run tests directly with HTTPXRequest because that's easier than providing dummy implementations for BaseRequest and we want to test HTTPXRequest anyway.""" + import asyncio import datetime as dtm import json @@ -591,7 +592,10 @@ async def make_assertion(self, **kwargs): assert code == HTTPStatus.OK async def test_do_request_params_with_data( - self, monkeypatch, httpx_request, mixed_rqs # noqa: F811 + self, + monkeypatch, + httpx_request, + mixed_rqs, # noqa: F811 ): async def make_assertion(self, **kwargs): method_assertion = kwargs.get("method") == "method" @@ -668,7 +672,11 @@ async def request(_, **kwargs): @pytest.mark.parametrize("media", [True, False]) async def test_do_request_write_timeout( - self, monkeypatch, media, httpx_request, input_media_photo # noqa: F811 + self, + monkeypatch, + media, + httpx_request, + input_media_photo, # noqa: F811 ): async def request(_, **kwargs): self.test_flag = kwargs.get("timeout") @@ -695,7 +703,11 @@ async def request(_, **kwargs): @pytest.mark.parametrize("init", [True, False]) async def test_setting_media_write_timeout( - self, monkeypatch, init, input_media_photo, recwarn # noqa: F811 + self, + monkeypatch, + init, + input_media_photo, # noqa: F811 + recwarn, ): httpx_request = HTTPXRequest(media_write_timeout=42) if init else HTTPXRequest() diff --git a/tests/test_bot.py b/tests/test_bot.py index 0e6e1355e3a..6ecf041f77a 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -596,9 +596,9 @@ def test_ext_bot_signature(self, name, method): signature = inspect.signature(method) ext_signature = inspect.signature(getattr(ExtBot, name)) - assert ( - ext_signature.return_annotation == signature.return_annotation - ), f"Wrong return annotation for method {name}" + assert ext_signature.return_annotation == signature.return_annotation, ( + f"Wrong return annotation for method {name}" + ) assert ( set(signature.parameters) == set(ext_signature.parameters) - global_extra_args - extra_args_per_method[name] @@ -606,15 +606,15 @@ def test_ext_bot_signature(self, name, method): for param_name, param in signature.parameters.items(): if param_name in different_hints_per_method[name]: continue - assert ( - param.annotation == ext_signature.parameters[param_name].annotation - ), f"Wrong annotation for parameter {param_name} of method {name}" - assert ( - param.default == ext_signature.parameters[param_name].default - ), f"Wrong default value for parameter {param_name} of method {name}" - assert ( - param.kind == ext_signature.parameters[param_name].kind - ), f"Wrong parameter kind for parameter {param_name} of method {name}" + assert param.annotation == ext_signature.parameters[param_name].annotation, ( + f"Wrong annotation for parameter {param_name} of method {name}" + ) + assert param.default == ext_signature.parameters[param_name].default, ( + f"Wrong default value for parameter {param_name} of method {name}" + ) + assert param.kind == ext_signature.parameters[param_name].kind, ( + f"Wrong parameter kind for parameter {param_name} of method {name}" + ) async def test_unknown_kwargs(self, offline_bot, monkeypatch): async def post(url, request_data: RequestData, *args, **kwargs): diff --git a/tests/test_botdescription.py b/tests/test_botdescription.py index e5826154741..2d9d6fe7234 100644 --- a/tests/test_botdescription.py +++ b/tests/test_botdescription.py @@ -41,9 +41,9 @@ class TestBotDescriptionWithoutRequest(BotDescriptionTestBase): def test_slot_behaviour(self, bot_description): for attr in bot_description.__slots__: assert getattr(bot_description, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(bot_description)) == len( - set(mro_slots(bot_description)) - ), "duplicate slot" + assert len(mro_slots(bot_description)) == len(set(mro_slots(bot_description))), ( + "duplicate slot" + ) def test_to_dict(self, bot_description): bot_description_dict = bot_description.to_dict() diff --git a/tests/test_checklists.py b/tests/test_checklists.py index dda79105437..96ab522d130 100644 --- a/tests/test_checklists.py +++ b/tests/test_checklists.py @@ -61,9 +61,9 @@ class TestChecklistTaskWithoutRequest(ChecklistTaskTestBase): def test_slot_behaviour(self, checklist_task): for attr in checklist_task.__slots__: assert getattr(checklist_task, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(checklist_task)) == len( - set(mro_slots(checklist_task)) - ), "duplicate slot" + assert len(mro_slots(checklist_task)) == len(set(mro_slots(checklist_task))), ( + "duplicate slot" + ) def test_to_dict(self, checklist_task): clt_dict = checklist_task.to_dict() @@ -307,9 +307,9 @@ class TestChecklistTasksDoneWithoutRequest(ChecklistTasksDoneTestBase): def test_slot_behaviour(self, checklist_tasks_done): for attr in checklist_tasks_done.__slots__: assert getattr(checklist_tasks_done, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(checklist_tasks_done)) == len( - set(mro_slots(checklist_tasks_done)) - ), "duplicate slot" + assert len(mro_slots(checklist_tasks_done)) == len(set(mro_slots(checklist_tasks_done))), ( + "duplicate slot" + ) def test_to_dict(self, checklist_tasks_done): cltd_dict = checklist_tasks_done.to_dict() diff --git a/tests/test_constants.py b/tests/test_constants.py index b97cc4f8eac..b7cc6483627 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -62,9 +62,9 @@ def test__all__(self): ) } actual = set(constants.__all__) - assert ( - actual == expected - ), f"Members {expected - actual} were not listed in constants.__all__" + assert actual == expected, ( + f"Members {expected - actual} were not listed in constants.__all__" + ) def test_message_attachment_type(self): assert all( @@ -226,9 +226,9 @@ def test_message_type_completeness(self, attribute): @pytest.mark.parametrize("member", constants.MessageType) def test_message_type_completeness_reverse(self, member): - assert self.is_type_attribute( - member.value - ), f"Additional member {member} in MessageType that should not be a message type" + assert self.is_type_attribute(member.value), ( + f"Additional member {member} in MessageType that should not be a message type" + ) @pytest.mark.parametrize("member", constants.MessageAttachmentType) def test_message_attachment_type_completeness(self, member): diff --git a/tests/test_copytextbutton.py b/tests/test_copytextbutton.py index 398a4bf5401..6678f25eeef 100644 --- a/tests/test_copytextbutton.py +++ b/tests/test_copytextbutton.py @@ -36,9 +36,9 @@ class TestCopyTextButtonWithoutRequest(CopyTextButtonTestBase): def test_slot_behaviour(self, copy_text_button): for attr in copy_text_button.__slots__: assert getattr(copy_text_button, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(copy_text_button)) == len( - set(mro_slots(copy_text_button)) - ), "duplicate slot" + assert len(mro_slots(copy_text_button)) == len(set(mro_slots(copy_text_button))), ( + "duplicate slot" + ) def test_de_json(self, offline_bot): json_dict = {"text": self.text} diff --git a/tests/test_enum_types.py b/tests/test_enum_types.py index 36a823eda46..21b8cd79def 100644 --- a/tests/test_enum_types.py +++ b/tests/test_enum_types.py @@ -25,8 +25,7 @@ telegram_ext_root = telegram_root / "ext" exclude_dirs = { # We touch passport stuff only if strictly necessary. - telegram_root - / "_passport", + telegram_root / "_passport", } exclude_patterns = { diff --git a/tests/test_forum.py b/tests/test_forum.py index 11bec6ea2f2..dc627eb8462 100644 --- a/tests/test_forum.py +++ b/tests/test_forum.py @@ -60,7 +60,6 @@ async def test_expected_values(self, emoji_id, forum_group_id, forum_topic_objec assert forum_topic_object.icon_custom_emoji_id == emoji_id def test_de_json(self, offline_bot, emoji_id, forum_group_id): - json_dict = { "message_thread_id": forum_group_id, "name": TEST_TOPIC_NAME, @@ -297,16 +296,15 @@ class TestForumTopicCreatedWithoutRequest: def test_slot_behaviour(self, topic_created): for attr in topic_created.__slots__: assert getattr(topic_created, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(topic_created)) == len( - set(mro_slots(topic_created)) - ), "duplicate slot" + assert len(mro_slots(topic_created)) == len(set(mro_slots(topic_created))), ( + "duplicate slot" + ) def test_expected_values(self, topic_created): assert topic_created.icon_color == TEST_TOPIC_ICON_COLOR assert topic_created.name == TEST_TOPIC_NAME def test_de_json(self, offline_bot): - json_dict = {"icon_color": TEST_TOPIC_ICON_COLOR, "name": TEST_TOPIC_NAME} action = ForumTopicCreated.de_json(json_dict, offline_bot) assert action.api_kwargs == {} diff --git a/tests/test_gifts.py b/tests/test_gifts.py index 2b676a6ee89..e1f10d43564 100644 --- a/tests/test_gifts.py +++ b/tests/test_gifts.py @@ -433,9 +433,9 @@ class TestAcceptedGiftTypesWithoutRequest(AcceptedGiftTypesTestBase): def test_slot_behaviour(self, accepted_gift_types): for attr in accepted_gift_types.__slots__: assert getattr(accepted_gift_types, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(accepted_gift_types)) == len( - set(mro_slots(accepted_gift_types)) - ), "duplicate slot" + assert len(mro_slots(accepted_gift_types)) == len(set(mro_slots(accepted_gift_types))), ( + "duplicate slot" + ) def test_de_json(self, offline_bot): json_dict = { diff --git a/tests/test_giveaway.py b/tests/test_giveaway.py index bf186002ce2..67c6e00200d 100644 --- a/tests/test_giveaway.py +++ b/tests/test_giveaway.py @@ -181,9 +181,9 @@ class TestGiveawayCreatedWithoutRequest: def test_slot_behaviour(self, giveaway_created): for attr in giveaway_created.__slots__: assert getattr(giveaway_created, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(giveaway_created)) == len( - set(mro_slots(giveaway_created)) - ), "duplicate slot" + assert len(mro_slots(giveaway_created)) == len(set(mro_slots(giveaway_created))), ( + "duplicate slot" + ) def test_de_json(self, bot): json_dict = { @@ -238,9 +238,9 @@ class TestGiveawayWinnersWithoutRequest: def test_slot_behaviour(self, giveaway_winners): for attr in giveaway_winners.__slots__: assert getattr(giveaway_winners, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(giveaway_winners)) == len( - set(mro_slots(giveaway_winners)) - ), "duplicate slot" + assert len(mro_slots(giveaway_winners)) == len(set(mro_slots(giveaway_winners))), ( + "duplicate slot" + ) def test_de_json(self, offline_bot): json_dict = { @@ -385,9 +385,9 @@ class TestGiveawayCompletedWithoutRequest: def test_slot_behaviour(self, giveaway_completed): for attr in giveaway_completed.__slots__: assert getattr(giveaway_completed, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(giveaway_completed)) == len( - set(mro_slots(giveaway_completed)) - ), "duplicate slot" + assert len(mro_slots(giveaway_completed)) == len(set(mro_slots(giveaway_completed))), ( + "duplicate slot" + ) def test_de_json(self, offline_bot): json_dict = { diff --git a/tests/test_inlinequeryresultsbutton.py b/tests/test_inlinequeryresultsbutton.py index 34f3e267d6e..22c9b5b0e26 100644 --- a/tests/test_inlinequeryresultsbutton.py +++ b/tests/test_inlinequeryresultsbutton.py @@ -52,7 +52,6 @@ def test_to_dict(self, inline_query_results_button): assert inline_query_results_button_dict["web_app"] == self.web_app.to_dict() def test_de_json(self, offline_bot): - json_dict = { "text": self.text, "start_parameter": self.start_parameter, diff --git a/tests/test_inputchecklist.py b/tests/test_inputchecklist.py index f21171eb5a3..cda5dbab8cd 100644 --- a/tests/test_inputchecklist.py +++ b/tests/test_inputchecklist.py @@ -46,9 +46,9 @@ class TestInputChecklistTaskWithoutRequest(InputChecklistTaskTestBase): def test_slot_behaviour(self, input_checklist_task): for attr in input_checklist_task.__slots__: assert getattr(input_checklist_task, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(input_checklist_task)) == len( - set(mro_slots(input_checklist_task)) - ), "duplicate slot" + assert len(mro_slots(input_checklist_task)) == len(set(mro_slots(input_checklist_task))), ( + "duplicate slot" + ) def test_expected_values(self, input_checklist_task): assert input_checklist_task.id == self.id @@ -117,9 +117,9 @@ class TestInputChecklistWithoutRequest(InputChecklistTestBase): def test_slot_behaviour(self, input_checklist): for attr in input_checklist.__slots__: assert getattr(input_checklist, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(input_checklist)) == len( - set(mro_slots(input_checklist)) - ), "duplicate slot" + assert len(mro_slots(input_checklist)) == len(set(mro_slots(input_checklist))), ( + "duplicate slot" + ) def test_expected_values(self, input_checklist): assert input_checklist.title == self.title diff --git a/tests/test_keyboardbuttonrequest.py b/tests/test_keyboardbuttonrequest.py index 93c5ef5d921..7fb43830954 100644 --- a/tests/test_keyboardbuttonrequest.py +++ b/tests/test_keyboardbuttonrequest.py @@ -44,9 +44,9 @@ class TestKeyboardButtonRequestUsersWithoutRequest(KeyboardButtonRequestUsersTes def test_slot_behaviour(self, request_users): for attr in request_users.__slots__: assert getattr(request_users, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(request_users)) == len( - set(mro_slots(request_users)) - ), "duplicate slot" + assert len(mro_slots(request_users)) == len(set(mro_slots(request_users))), ( + "duplicate slot" + ) def test_to_dict(self, request_users): request_users_dict = request_users.to_dict() diff --git a/tests/test_maybeinaccessiblemessage.py b/tests/test_maybeinaccessiblemessage.py index 4e715ed8a65..af55422bf2e 100644 --- a/tests/test_maybeinaccessiblemessage.py +++ b/tests/test_maybeinaccessiblemessage.py @@ -44,9 +44,9 @@ class MaybeInaccessibleMessageTestBase: class TestMaybeInaccessibleMessageWithoutRequest(MaybeInaccessibleMessageTestBase): def test_slot_behaviour(self, maybe_inaccessible_message): for attr in maybe_inaccessible_message.__slots__: - assert ( - getattr(maybe_inaccessible_message, attr, "err") != "err" - ), f"got extra slot '{attr}'" + assert getattr(maybe_inaccessible_message, attr, "err") != "err", ( + f"got extra slot '{attr}'" + ) assert len(mro_slots(maybe_inaccessible_message)) == len( set(mro_slots(maybe_inaccessible_message)) ), "duplicate slot" diff --git a/tests/test_message.py b/tests/test_message.py index ba8fa439f4d..1c8a12ac9c4 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -1389,8 +1389,7 @@ def test_compute_quote_position_and_entities_false_index(self, message): message.text = "AA" with pytest.raises( ValueError, - match="You requested the 5-th occurrence of 'A', " - "but this text appears only 2 times.", + match="You requested the 5-th occurrence of 'A', but this text appears only 2 times.", ): message.compute_quote_position_and_entities("A", 5) diff --git a/tests/test_modules.py b/tests/test_modules.py index eead2b183f4..12096c1d52d 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -19,6 +19,7 @@ """This tests whether our submodules have __all__ or not. Additionally also tests if all public submodules are included in __all__ for __init__'s. """ + import importlib import os from pathlib import Path diff --git a/tests/test_official/test_official.py b/tests/test_official/test_official.py index b699a2b2eea..5e50e133047 100644 --- a/tests/test_official/test_official.py +++ b/tests/test_official/test_official.py @@ -73,19 +73,19 @@ def test_check_method(tg_method: TelegramMethod) -> None: for tg_parameter in tg_method.method_parameters: # Check if parameter is present in our method ptb_param = sig.parameters.get(tg_parameter.param_name) - assert ( - ptb_param is not None - ), f"Parameter {tg_parameter.param_name} not found in {ptb_method.__name__}" + assert ptb_param is not None, ( + f"Parameter {tg_parameter.param_name} not found in {ptb_method.__name__}" + ) # Now check if the parameter is required or not - assert check_required_param( - tg_parameter, ptb_param, ptb_method.__name__ - ), f"Param {ptb_param.name!r} of {ptb_method.__name__!r} requirement mismatch" + assert check_required_param(tg_parameter, ptb_param, ptb_method.__name__), ( + f"Param {ptb_param.name!r} of {ptb_method.__name__!r} requirement mismatch" + ) # Check if type annotation is present - assert ( - ptb_param.annotation is not inspect.Parameter.empty - ), f"Param {ptb_param.name!r} of {ptb_method.__name__!r} should have a type annotation!" + assert ptb_param.annotation is not inspect.Parameter.empty, ( + f"Param {ptb_param.name!r} of {ptb_method.__name__!r} should have a type annotation!" + ) # Check if type annotation is correct correct_type_hint, expected_type_hint = check_param_type( ptb_param, @@ -100,9 +100,9 @@ def test_check_method(tg_method: TelegramMethod) -> None: # Now we will check that we don't pass default values if the parameter is not required. if ptb_param.default is not inspect.Parameter.empty: # If there is a default argument... default_arg_none = check_defaults_type(ptb_param) # check if it's None - assert ( - default_arg_none - ), f"Param {ptb_param.name!r} of {ptb_method.__name__!r} should be `None`" + assert default_arg_none, ( + f"Param {ptb_param.name!r} of {ptb_method.__name__!r} should be `None`" + ) checked.append(tg_parameter.param_name) expected_additional_args = GLOBALLY_IGNORED_PARAMETERS.copy() @@ -110,9 +110,9 @@ def test_check_method(tg_method: TelegramMethod) -> None: expected_additional_args |= backwards_compat_kwargs(tg_method.method_name) unexpected_args = (sig.parameters.keys() ^ checked) - expected_additional_args - assert ( - unexpected_args == set() - ), f"In {ptb_method.__qualname__}, unexpected args were found: {unexpected_args}." + assert unexpected_args == set(), ( + f"In {ptb_method.__qualname__}, unexpected args were found: {unexpected_args}." + ) kw_or_positional_args = [ p.name for p in sig.parameters.values() if p.kind != inspect.Parameter.KEYWORD_ONLY @@ -158,14 +158,14 @@ def test_check_object(tg_class: TelegramClass) -> None: assert ptb_param is not None, f"Attribute {field} not found in {obj.__name__}" # Now check if the parameter is required or not - assert check_required_param( - tg_parameter, ptb_param, obj.__name__ - ), f"Param {ptb_param.name!r} of {obj.__name__!r} requirement mismatch" + assert check_required_param(tg_parameter, ptb_param, obj.__name__), ( + f"Param {ptb_param.name!r} of {obj.__name__!r} requirement mismatch" + ) # Check if type annotation is present - assert ( - ptb_param.annotation is not inspect.Parameter.empty - ), f"Param {ptb_param.name!r} of {obj.__name__!r} should have a type annotation" + assert ptb_param.annotation is not inspect.Parameter.empty, ( + f"Param {ptb_param.name!r} of {obj.__name__!r} should have a type annotation" + ) # Check if type annotation is correct correct_type_hint, expected_type_hint = check_param_type(ptb_param, tg_parameter, obj) @@ -177,9 +177,9 @@ def test_check_object(tg_class: TelegramClass) -> None: # Now we will check that we don't pass default values if the parameter is not required. if ptb_param.default is not inspect.Parameter.empty: # If there is a default argument... default_arg_none = check_defaults_type(ptb_param) # check if its None - assert ( - default_arg_none - ), f"Param {ptb_param.name!r} of {obj.__name__!r} should be `None`" + assert default_arg_none, ( + f"Param {ptb_param.name!r} of {obj.__name__!r} should be `None`" + ) checked.add(field) @@ -188,6 +188,6 @@ def test_check_object(tg_class: TelegramClass) -> None: expected_additional_args |= backwards_compat_kwargs(tg_class.class_name) unexpected_args = (sig.parameters.keys() ^ checked) - expected_additional_args - assert ( - unexpected_args == set() - ), f"In {tg_class.class_name}, unexpected args were found: {unexpected_args}." + assert unexpected_args == set(), ( + f"In {tg_class.class_name}, unexpected args were found: {unexpected_args}." + ) diff --git a/tests/test_paidmessagepricechanged.py b/tests/test_paidmessagepricechanged.py index b97eafbab93..a41d292c73d 100644 --- a/tests/test_paidmessagepricechanged.py +++ b/tests/test_paidmessagepricechanged.py @@ -35,9 +35,9 @@ def paid_message_price_changed(): class TestPaidMessagePriceChangedWithoutRequest(PaidMessagePriceChangedTestBase): def test_slot_behaviour(self, paid_message_price_changed): for attr in paid_message_price_changed.__slots__: - assert ( - getattr(paid_message_price_changed, attr, "err") != "err" - ), f"got extra slot '{attr}'" + assert getattr(paid_message_price_changed, attr, "err") != "err", ( + f"got extra slot '{attr}'" + ) assert len(mro_slots(paid_message_price_changed)) == len( set(mro_slots(paid_message_price_changed)) ), "duplicate slot" diff --git a/tests/test_poll.py b/tests/test_poll.py index 484e18710a2..1b003f11f29 100644 --- a/tests/test_poll.py +++ b/tests/test_poll.py @@ -50,12 +50,11 @@ class TestInputPollOptionWithoutRequest(InputPollOptionTestBase): def test_slot_behaviour(self, input_poll_option): for attr in input_poll_option.__slots__: assert getattr(input_poll_option, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(input_poll_option)) == len( - set(mro_slots(input_poll_option)) - ), "duplicate slot" + assert len(mro_slots(input_poll_option)) == len(set(mro_slots(input_poll_option))), ( + "duplicate slot" + ) def test_de_json(self): - json_dict = { "text": self.text, "text_parse_mode": self.text_parse_mode, diff --git a/tests/test_reaction.py b/tests/test_reaction.py index af4e3f6fb15..3ae57ec60b1 100644 --- a/tests/test_reaction.py +++ b/tests/test_reaction.py @@ -221,9 +221,9 @@ class TestReactionCountWithoutRequest: def test_slot_behaviour(self, reaction_count): for attr in reaction_count.__slots__: assert getattr(reaction_count, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(reaction_count)) == len( - set(mro_slots(reaction_count)) - ), "duplicate slot" + assert len(mro_slots(reaction_count)) == len(set(mro_slots(reaction_count))), ( + "duplicate slot" + ) def test_de_json(self, offline_bot): json_dict = { diff --git a/tests/test_reply.py b/tests/test_reply.py index 6d29c910761..0c144175640 100644 --- a/tests/test_reply.py +++ b/tests/test_reply.py @@ -79,9 +79,9 @@ class TestExternalReplyInfoWithoutRequest(ExternalReplyInfoTestBase): def test_slot_behaviour(self, external_reply_info): for attr in external_reply_info.__slots__: assert getattr(external_reply_info, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(external_reply_info)) == len( - set(mro_slots(external_reply_info)) - ), "duplicate slot" + assert len(mro_slots(external_reply_info)) == len(set(mro_slots(external_reply_info))), ( + "duplicate slot" + ) def test_de_json(self, offline_bot): json_dict = { @@ -238,9 +238,9 @@ class TestReplyParametersWithoutRequest(ReplyParametersTestBase): def test_slot_behaviour(self, reply_parameters): for attr in reply_parameters.__slots__: assert getattr(reply_parameters, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(reply_parameters)) == len( - set(mro_slots(reply_parameters)) - ), "duplicate slot" + assert len(mro_slots(reply_parameters)) == len(set(mro_slots(reply_parameters))), ( + "duplicate slot" + ) def test_de_json(self, offline_bot): json_dict = { diff --git a/tests/test_telegramobject.py b/tests/test_telegramobject.py index 722acdb1624..fecc0278601 100644 --- a/tests/test_telegramobject.py +++ b/tests/test_telegramobject.py @@ -146,9 +146,9 @@ def test_subclasses_have_api_kwargs(self, cls): if cls is TelegramObject: # TelegramObject doesn't have a super class return - assert "api_kwargs=api_kwargs" in inspect.getsource( - cls.__init__ - ), f"{cls.__name__} doesn't seem to pass `api_kwargs` to `super().__init__`" + assert "api_kwargs=api_kwargs" in inspect.getsource(cls.__init__), ( + f"{cls.__name__} doesn't seem to pass `api_kwargs` to `super().__init__`" + ) def test_de_json_arbitrary_exceptions(self, bot): class SubClass(TelegramObject): diff --git a/tests/test_uniquegift.py b/tests/test_uniquegift.py index 926cdcae91f..bb317a0e9f7 100644 --- a/tests/test_uniquegift.py +++ b/tests/test_uniquegift.py @@ -154,9 +154,9 @@ class TestUniqueGiftModelWithoutRequest(UniqueGiftModelTestBase): def test_slot_behaviour(self, unique_gift_model): for attr in unique_gift_model.__slots__: assert getattr(unique_gift_model, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(unique_gift_model)) == len( - set(mro_slots(unique_gift_model)) - ), "duplicate slot" + assert len(mro_slots(unique_gift_model)) == len(set(mro_slots(unique_gift_model))), ( + "duplicate slot" + ) def test_de_json(self, offline_bot): json_dict = { @@ -211,9 +211,9 @@ class TestUniqueGiftSymbolWithoutRequest(UniqueGiftSymbolTestBase): def test_slot_behaviour(self, unique_gift_symbol): for attr in unique_gift_symbol.__slots__: assert getattr(unique_gift_symbol, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(unique_gift_symbol)) == len( - set(mro_slots(unique_gift_symbol)) - ), "duplicate slot" + assert len(mro_slots(unique_gift_symbol)) == len(set(mro_slots(unique_gift_symbol))), ( + "duplicate slot" + ) def test_de_json(self, offline_bot): json_dict = { @@ -268,9 +268,9 @@ class TestUniqueGiftBackdropWithoutRequest(UniqueGiftBackdropTestBase): def test_slot_behaviour(self, unique_gift_backdrop): for attr in unique_gift_backdrop.__slots__: assert getattr(unique_gift_backdrop, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(unique_gift_backdrop)) == len( - set(mro_slots(unique_gift_backdrop)) - ), "duplicate slot" + assert len(mro_slots(unique_gift_backdrop)) == len(set(mro_slots(unique_gift_backdrop))), ( + "duplicate slot" + ) def test_de_json(self, offline_bot): json_dict = { @@ -326,9 +326,9 @@ class UniqueGiftBackdropColorsTestBase: class TestUniqueGiftBackdropColorsWithoutRequest(UniqueGiftBackdropColorsTestBase): def test_slot_behaviour(self, unique_gift_backdrop_colors): for attr in unique_gift_backdrop_colors.__slots__: - assert ( - getattr(unique_gift_backdrop_colors, attr, "err") != "err" - ), f"got extra slot '{attr}'" + assert getattr(unique_gift_backdrop_colors, attr, "err") != "err", ( + f"got extra slot '{attr}'" + ) assert len(mro_slots(unique_gift_backdrop_colors)) == len( set(mro_slots(unique_gift_backdrop_colors)) ), "duplicate slot" @@ -424,9 +424,9 @@ class TestUniqueGiftInfoWithoutRequest(UniqueGiftInfoTestBase): def test_slot_behaviour(self, unique_gift_info): for attr in unique_gift_info.__slots__: assert getattr(unique_gift_info, attr, "err") != "err", f"got extra slot '{attr}'" - assert len(mro_slots(unique_gift_info)) == len( - set(mro_slots(unique_gift_info)) - ), "duplicate slot" + assert len(mro_slots(unique_gift_info)) == len(set(mro_slots(unique_gift_info))), ( + "duplicate slot" + ) def test_de_json(self, offline_bot): json_dict = { diff --git a/tests/test_videochat.py b/tests/test_videochat.py index df8151940cf..74be008207b 100644 --- a/tests/test_videochat.py +++ b/tests/test_videochat.py @@ -186,7 +186,6 @@ def test_expected_values(self): assert VideoChatScheduled(self.start_date).start_date == self.start_date def test_de_json(self, offline_bot): - json_dict = {"start_date": to_timestamp(self.start_date)} video_chat_scheduled = VideoChatScheduled.de_json(json_dict, offline_bot) assert video_chat_scheduled.api_kwargs == {} From 069f83a4881f27adfd725c1d1ca30a7a5f4de493 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Mon, 28 Jul 2025 18:45:08 -0700 Subject: [PATCH 3/7] Remove additional_dependencies in pre-commit for ruff --- .pre-commit-config.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b38baf641d4..26c52a23da1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,12 +12,6 @@ repos: # Run the linter: - id: ruff name: ruff - # additional_dependencies: - # - httpx~=0.27 - # - tornado~=6.4 - # - APScheduler~=3.10.4 - # - cachetools>=5.3.3,<5.5.0 - # - aiolimiter~=1.1,<1.3 # Run the formatter: - id: ruff-format - repo: https://github.com/PyCQA/pylint From 7d3e592e847255fdc2b8f750069ca3318b82be64 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Mon, 28 Jul 2025 18:47:30 -0700 Subject: [PATCH 4/7] Update contributing guidelines --- .github/CONTRIBUTING.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/CONTRIBUTING.rst b/.github/CONTRIBUTING.rst index 15049ac55af..db8a54bd371 100644 --- a/.github/CONTRIBUTING.rst +++ b/.github/CONTRIBUTING.rst @@ -87,7 +87,7 @@ Here's how to make a one-off code change. - Documenting types of global variables and complex types of class members can be done using the Sphinx docstring convention. - - In addition, PTB uses some formatting/styling and linting tools in the pre-commit setup. Some of those tools also have command line tools that can help to run these tools outside of the pre-commit step. If you'd like to leverage that, please have a look at the `pre-commit config file`_ for an overview of which tools (and which versions of them) are used. For example, we use `Black`_ for code formatting. Plugins for Black exist for some `popular editors`_. You can use those instead of manually formatting everything. + - In addition, PTB uses some formatting/styling and linting tools in the pre-commit setup. Some of those tools also have command line tools that can help to run these tools outside of the pre-commit step. If you'd like to leverage that, please have a look at the `pre-commit config file`_ for an overview of which tools (and which versions of them) are used. For example, we use `Ruff`_ for linting and formatting. - Please ensure that the code you write is well-tested and that all automated tests still pass. We have dedicated an `testing page`_ to help you with that. @@ -288,8 +288,7 @@ to add new required arguments. It's also more explicit and easier to read. .. _`MyPy`: https://mypy.readthedocs.io/en/stable/index.html .. _`here`: https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html .. _`pre-commit config file`: https://github.com/python-telegram-bot/python-telegram-bot/blob/master/.pre-commit-config.yaml -.. _`Black`: https://black.readthedocs.io/en/stable/index.html -.. _`popular editors`: https://black.readthedocs.io/en/stable/integrations/editors.html +.. _`Ruff`: https://docs.astral.sh/ruff/ .. _`RTD`: https://docs.python-telegram-bot.org/ .. _`RTD build`: https://docs.python-telegram-bot.org/en/doc-fixes .. _`CSI`: https://standards.mousepawmedia.com/en/stable/csi.html From e7d462f5cf975d3a8db83241f31b6bfee27dd0ba Mon Sep 17 00:00:00 2001 From: harshil21 <37377066+harshil21@users.noreply.github.com> Date: Tue, 29 Jul 2025 01:48:50 +0000 Subject: [PATCH 5/7] Add chango fragment for PR #4886 --- changes/unreleased/4886.XSHPk83uhDQdYzurbb4xx9.toml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changes/unreleased/4886.XSHPk83uhDQdYzurbb4xx9.toml diff --git a/changes/unreleased/4886.XSHPk83uhDQdYzurbb4xx9.toml b/changes/unreleased/4886.XSHPk83uhDQdYzurbb4xx9.toml new file mode 100644 index 00000000000..31aac7c0f10 --- /dev/null +++ b/changes/unreleased/4886.XSHPk83uhDQdYzurbb4xx9.toml @@ -0,0 +1,5 @@ +internal = "Remove `black`, `isort`, `flake8`, and `pyupgrade` in favor of Ruff" +[[pull_requests]] +uid = "4886" +author_uid = "harshil21" +closes_threads = [] From ee2d6683efbfbe4d305a7dd751ea9018bd18c416 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Wed, 30 Jul 2025 04:19:39 -0700 Subject: [PATCH 6/7] Remove setup.cfg and bump ruff again --- .pre-commit-config.yaml | 2 +- setup.cfg | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 setup.cfg diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 26c52a23da1..2fe878437bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.12.5' + rev: 'v0.12.7' hooks: # Run the linter: - id: ruff diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index c24e78bc4e1..00000000000 --- a/setup.cfg +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -max-line-length = 99 -ignore = W503, W605 -extend-ignore = E203, E704 -exclude = docs/source/conf.py From 19c3963e3170d402e7c27982129e48d331d166d0 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Wed, 30 Jul 2025 16:20:32 -0700 Subject: [PATCH 7/7] Review: changelog, ruff-check --- .pre-commit-config.yaml | 2 +- changes/unreleased/4886.XSHPk83uhDQdYzurbb4xx9.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2fe878437bb..474dd749adb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: rev: 'v0.12.7' hooks: # Run the linter: - - id: ruff + - id: ruff-check name: ruff # Run the formatter: - id: ruff-format diff --git a/changes/unreleased/4886.XSHPk83uhDQdYzurbb4xx9.toml b/changes/unreleased/4886.XSHPk83uhDQdYzurbb4xx9.toml index 31aac7c0f10..25cf57c755c 100644 --- a/changes/unreleased/4886.XSHPk83uhDQdYzurbb4xx9.toml +++ b/changes/unreleased/4886.XSHPk83uhDQdYzurbb4xx9.toml @@ -1,4 +1,4 @@ -internal = "Remove `black`, `isort`, `flake8`, and `pyupgrade` in favor of Ruff" +internal = "Remove ``black``, ``isort``, ``flake8``, and ``pyupgrade`` in favor of ``ruff``" [[pull_requests]] uid = "4886" author_uid = "harshil21" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy