diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a6002c846bf..4b091946e44 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.11.9' + rev: 'v0.12.2' hooks: - id: ruff name: ruff @@ -25,11 +25,11 @@ repos: - --diff - --check - repo: https://github.com/PyCQA/flake8 - rev: 7.2.0 + rev: 7.3.0 hooks: - id: flake8 - repo: https://github.com/PyCQA/pylint - rev: v3.3.6 + rev: v3.3.7 hooks: - id: pylint files: ^(?!(tests|docs)).*\.py$ @@ -41,7 +41,7 @@ repos: - aiolimiter~=1.1,<1.3 - . # this basically does `pip install -e .` - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.15.0 + rev: v1.16.1 hooks: - id: mypy name: mypy-ptb @@ -68,7 +68,7 @@ repos: - cachetools>=5.3.3,<5.5.0 - . # this basically does `pip install -e .` - repo: https://github.com/asottile/pyupgrade - rev: v3.19.1 + rev: v3.20.0 hooks: - id: pyupgrade args: diff --git a/changes/unreleased/4858.ajt46xDsbfzFqcghJ2rP6g.toml b/changes/unreleased/4858.ajt46xDsbfzFqcghJ2rP6g.toml new file mode 100644 index 00000000000..54620eebed2 --- /dev/null +++ b/changes/unreleased/4858.ajt46xDsbfzFqcghJ2rP6g.toml @@ -0,0 +1,5 @@ +internal = "Bump `pre-commit` Hooks to Latest Versions" +[[pull_requests]] +uid = "4858" +author_uid = "pre-commit-ci" +closes_threads = [] diff --git a/src/telegram/__main__.py b/src/telegram/__main__.py index 7d291b2ae1e..90e349eca5d 100644 --- a/src/telegram/__main__.py +++ b/src/telegram/__main__.py @@ -17,7 +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/]. # pylint: disable=missing-module-docstring -# ruff: noqa: T201, D100, S603, S607 +# ruff: noqa: T201, D100, S607 import subprocess import sys from typing import Optional diff --git a/src/telegram/_chatfullinfo.py b/src/telegram/_chatfullinfo.py index e1abdb65a1e..01439536b84 100644 --- a/src/telegram/_chatfullinfo.py +++ b/src/telegram/_chatfullinfo.py @@ -573,7 +573,7 @@ def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "ChatFullInfo": data.get("accepted_gift_types"), AcceptedGiftTypes, bot ) - from telegram import ( # pylint: disable=import-outside-toplevel + from telegram import ( # pylint: disable=import-outside-toplevel # noqa: PLC0415 BusinessIntro, BusinessLocation, BusinessOpeningHours, diff --git a/src/telegram/_giveaway.py b/src/telegram/_giveaway.py index d7d086e6548..e41f8472b8f 100644 --- a/src/telegram/_giveaway.py +++ b/src/telegram/_giveaway.py @@ -371,7 +371,9 @@ 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 Message # pylint: disable=import-outside-toplevel + from telegram._message import ( # noqa: PLC0415 # pylint: disable=import-outside-toplevel + Message, + ) data["giveaway_message"] = de_json_optional(data.get("giveaway_message"), Message, bot) diff --git a/src/telegram/_message.py b/src/telegram/_message.py index 274089bff50..7736fce459f 100644 --- a/src/telegram/_message.py +++ b/src/telegram/_message.py @@ -1402,16 +1402,16 @@ def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "Message": ) # Unfortunately, this needs to be here due to cyclic imports - from telegram._giveaway import ( # pylint: disable=import-outside-toplevel + from telegram._giveaway import ( # pylint: disable=C0415 # noqa: PLC0415 Giveaway, GiveawayCompleted, GiveawayCreated, GiveawayWinners, ) - from telegram._messageorigin import ( # pylint: disable=import-outside-toplevel + from telegram._messageorigin import ( # pylint: disable=C0415 # noqa: PLC0415 MessageOrigin, ) - from telegram._reply import ( # pylint: disable=import-outside-toplevel + from telegram._reply import ( # pylint: disable=import-outside-toplevel # noqa: PLC0415 ExternalReplyInfo, TextQuote, ) diff --git a/src/telegram/_passport/encryptedpassportelement.py b/src/telegram/_passport/encryptedpassportelement.py index c231c51640b..65f88e7a69b 100644 --- a/src/telegram/_passport/encryptedpassportelement.py +++ b/src/telegram/_passport/encryptedpassportelement.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# flake8: noqa: E501 # A library that provides a Python interface to the Telegram Bot API # Copyright (C) 2015-2025 # Leandro Toledo de Souza diff --git a/src/telegram/_utils/files.py b/src/telegram/_utils/files.py index a750e1512e1..9bacce86f3c 100644 --- a/src/telegram/_utils/files.py +++ b/src/telegram/_utils/files.py @@ -134,7 +134,7 @@ def parse_file_input( # pylint: disable=too-many-return-statements :attr:`file_input`, in case it's no valid file input. """ # Importing on file-level yields cyclic Import Errors - from telegram import InputFile # pylint: disable=import-outside-toplevel + from telegram import InputFile # pylint: disable=import-outside-toplevel # noqa: PLC0415 if isinstance(file_input, str) and file_input.startswith("file://"): if not local_mode: diff --git a/src/telegram/ext/_application.py b/src/telegram/ext/_application.py index d287b3a375d..51f739b3e27 100644 --- a/src/telegram/ext/_application.py +++ b/src/telegram/ext/_application.py @@ -455,7 +455,9 @@ def builder() -> "InitApplicationBuilder": .. versionadded:: 20.0 """ # Unfortunately this needs to be here due to cyclical imports - from telegram.ext import ApplicationBuilder # pylint: disable=import-outside-toplevel + from telegram.ext import ( # noqa: PLC0415 # pylint: disable=import-outside-toplevel + ApplicationBuilder, + ) return ApplicationBuilder() @@ -498,7 +500,7 @@ async def initialize(self) -> None: # Unfortunately due to circular imports this has to be here # pylint: disable=import-outside-toplevel - from telegram.ext._handlers.conversationhandler import ConversationHandler + from telegram.ext._handlers.conversationhandler import ConversationHandler # noqa: PLC0415 # Initialize the persistent conversation handlers with the stored states for handler in itertools.chain.from_iterable(self.handlers.values()): @@ -1369,7 +1371,7 @@ def add_handler(self, handler: BaseHandler[Any, CCT, Any], group: int = DEFAULT_ """ # Unfortunately due to circular imports this has to be here # pylint: disable=import-outside-toplevel - from telegram.ext._handlers.conversationhandler import ConversationHandler + from telegram.ext._handlers.conversationhandler import ConversationHandler # noqa: PLC0415 if not isinstance(handler, BaseHandler): raise TypeError(f"handler is not an instance of {BaseHandler.__name__}") @@ -1735,7 +1737,7 @@ async def __update_persistence(self) -> None: # Unfortunately due to circular imports this has to be here # pylint: disable=import-outside-toplevel - from telegram.ext._handlers.conversationhandler import PendingState + from telegram.ext._handlers.conversationhandler import PendingState # noqa: PLC0415 for name, (key, new_state) in itertools.chain.from_iterable( zip(itertools.repeat(name), states_dict.pop_accessed_write_items()) diff --git a/src/telegram/ext/_handlers/conversationhandler.py b/src/telegram/ext/_handlers/conversationhandler.py index dd824bf5601..d0a3734d61b 100644 --- a/src/telegram/ext/_handlers/conversationhandler.py +++ b/src/telegram/ext/_handlers/conversationhandler.py @@ -298,7 +298,7 @@ def __init__( block: DVType[bool] = DEFAULT_TRUE, ): # these imports need to be here because of circular import error otherwise - from telegram.ext import ( # pylint: disable=import-outside-toplevel + from telegram.ext import ( # pylint: disable=import-outside-toplevel # noqa: PLC0415 PollAnswerHandler, PollHandler, PreCheckoutQueryHandler, diff --git a/src/telegram/ext/filters.py b/src/telegram/ext/filters.py index 6322dafd296..f3272147442 100644 --- a/src/telegram/ext/filters.py +++ b/src/telegram/ext/filters.py @@ -2707,7 +2707,7 @@ def user_ids(self) -> frozenset[int]: @user_ids.setter def user_ids(self, user_id: SCT[int]) -> None: - self.chat_ids = user_id # type: ignore[assignment] + self.chat_ids = user_id def add_user_ids(self, user_id: SCT[int]) -> None: """ @@ -2845,7 +2845,7 @@ def bot_ids(self) -> frozenset[int]: @bot_ids.setter def bot_ids(self, bot_id: SCT[int]) -> None: - self.chat_ids = bot_id # type: ignore[assignment] + self.chat_ids = bot_id def add_bot_ids(self, bot_id: SCT[int]) -> None: """ diff --git a/src/telegram/helpers.py b/src/telegram/helpers.py index 81dd4b6c11a..494f26b716f 100644 --- a/src/telegram/helpers.py +++ b/src/telegram/helpers.py @@ -125,7 +125,10 @@ def effective_message_type(entity: Union["Message", "Update"]) -> Optional[str]: """ # Importing on file-level yields cyclic Import Errors - from telegram import Message, Update # pylint: disable=import-outside-toplevel + from telegram import ( # pylint: disable=import-outside-toplevel # noqa: PLC0415 + Message, + Update, + ) if isinstance(entity, Message): message = entity diff --git a/tests/_utils/test_datetime.py b/tests/_utils/test_datetime.py index 8628f0c109f..06d252a64a2 100644 --- a/tests/_utils/test_datetime.py +++ b/tests/_utils/test_datetime.py @@ -65,7 +65,7 @@ def test_localize_utc(self): @pytest.mark.skipif(not TEST_WITH_OPT_DEPS, reason="pytz not installed") def test_localize_pytz(self): dt = dtm.datetime(2023, 1, 1, 12, 0, 0) - import pytz + import pytz # noqa: PLC0415 tzinfo = pytz.timezone("Europe/Berlin") localized_dt = tg_dtm.localize(dt, tzinfo) diff --git a/tests/ext/_utils/test_stack.py b/tests/ext/_utils/test_stack.py index 369098685c0..41fa1a61446 100644 --- a/tests/ext/_utils/test_stack.py +++ b/tests/ext/_utils/test_stack.py @@ -80,7 +80,7 @@ def caller_func(): symlink_to(symlink_file, temp_file) sys.path.append(tmp_path.as_posix()) - from caller_link import caller_func + from caller_link import caller_func # noqa: PLC0415 frame = caller_func() assert was_called_by(frame, temp_file) @@ -111,7 +111,7 @@ def outer_func(): symlink_to(symlink_file2, temp_file2) sys.path.append(tmp_path.as_posix()) - from outer_link import outer_func + from outer_link import outer_func # noqa: PLC0415 frame = outer_func() assert was_called_by(frame, temp_file2) diff --git a/tests/ext/test_conversationhandler.py b/tests/ext/test_conversationhandler.py index 64959f47f47..4a5ceb68394 100644 --- a/tests/ext/test_conversationhandler.py +++ b/tests/ext/test_conversationhandler.py @@ -20,6 +20,7 @@ import asyncio import functools import logging +from copy import copy from pathlib import Path from warnings import filterwarnings @@ -307,8 +308,6 @@ def test_repr_no_truncation(self): ) def test_repr_with_truncation(self): - from copy import copy - states = copy(self.drinking_states) # there are exactly 3 drinking states. adding one more to make sure it's truncated states["extra_to_be_truncated"] = [CommandHandler("foo", self.start)] diff --git a/tests/ext/test_defaults.py b/tests/ext/test_defaults.py index 32f4b0c3800..a6c6ca3b047 100644 --- a/tests/ext/test_defaults.py +++ b/tests/ext/test_defaults.py @@ -42,7 +42,7 @@ def test_utc(self): @pytest.mark.skipif(not TEST_WITH_OPT_DEPS, reason="pytz not installed") def test_pytz_deprecation(self, recwarn): - import pytz + import pytz # noqa: PLC0415 with pytest.warns(PTBDeprecationWarning, match="pytz") as record: Defaults(tzinfo=pytz.timezone("Europe/Berlin")) diff --git a/tests/test_official/helpers.py b/tests/test_official/helpers.py index f2fcf890344..8fb08a01bd5 100644 --- a/tests/test_official/helpers.py +++ b/tests/test_official/helpers.py @@ -93,7 +93,7 @@ def is_parameter_required_by_tg(field: str) -> bool: def wrap_with_none(tg_parameter: "TelegramParameter", mapped_type: Any, obj: object) -> type: """Adds `None` to type annotation if the parameter isn't required. Respects ignored params.""" # have to import here to avoid circular imports - from tests.test_official.exceptions import ignored_param_requirements + from tests.test_official.exceptions import ignored_param_requirements # noqa: PLC0415 if tg_parameter.param_name in ignored_param_requirements(obj.__name__): return mapped_type | type(None)