Bump pre-commit Hooks to Latest Versions (#4748)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com>
This commit is contained in:
pre-commit-ci[bot]
2025-05-12 21:23:25 +02:00
committed by GitHub
parent 2fc04e1e10
commit c34e19edfd
25 changed files with 42 additions and 38 deletions
+6 -6
View File
@@ -7,7 +7,7 @@ ci:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.8.6'
rev: 'v0.11.9'
hooks:
- id: ruff
name: ruff
@@ -18,18 +18,18 @@ repos:
- cachetools>=5.3.3,<5.5.0
- aiolimiter~=1.1,<1.3
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.10.0
rev: 25.1.0
hooks:
- id: black
args:
- --diff
- --check
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
rev: 7.2.0
hooks:
- id: flake8
- repo: https://github.com/PyCQA/pylint
rev: v3.3.3
rev: v3.3.6
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.14.1
rev: v1.15.0
hooks:
- id: mypy
name: mypy-ptb
@@ -74,7 +74,7 @@ repos:
args:
- --py39-plus
- repo: https://github.com/pycqa/isort
rev: 5.13.2
rev: 6.0.1
hooks:
- id: isort
name: isort
@@ -0,0 +1,5 @@
internal = "Bump `pre-commit` Hooks to Latest Versions"
[[pull_requests]]
uid = "4748"
author_uid = "pre-commit-ci"
closes_threads = []
+7 -3
View File
@@ -15,12 +15,12 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
import collections.abc
import contextlib
import inspect
import re
import typing
from pathlib import Path
from typing import TYPE_CHECKING
from sphinx.application import Sphinx
@@ -37,6 +37,10 @@ from docs.auxil.kwargs_insertion import (
)
from docs.auxil.link_code import LINE_NUMBERS
if TYPE_CHECKING:
import collections.abc
ADMONITION_INSERTER = AdmonitionInserter()
# Some base classes are implementation detail
@@ -128,7 +132,7 @@ def autodoc_process_docstring(
insert_idx += len(effective_insert)
ADMONITION_INSERTER.insert_admonitions(
obj=typing.cast(collections.abc.Callable, obj),
obj=typing.cast("collections.abc.Callable", obj),
docstring_lines=lines,
)
@@ -136,7 +140,7 @@ def autodoc_process_docstring(
# (where applicable)
if what == "class":
ADMONITION_INSERTER.insert_admonitions(
obj=typing.cast(type, obj), # since "what" == class, we know it's not just object
obj=typing.cast("type", obj), # since "what" == class, we know it's not just object
docstring_lines=lines,
)
+1 -1
View File
@@ -69,7 +69,7 @@ async def list_button(update: Update, context: ContextTypes.DEFAULT_TYPE) -> Non
# Get the data from the callback_data.
# If you're using a type checker like MyPy, you'll have to use typing.cast
# to make the checker get the expected type of the callback_data
number, number_list = cast(tuple[int, list[int]], query.data)
number, number_list = cast("tuple[int, list[int]]", query.data)
# append the number to the list
number_list.append(number)
+1 -2
View File
@@ -125,8 +125,7 @@ line-length = 99
show-fixes = true
[tool.ruff.lint]
preview = true
explicit-preview-rules = true # TODO: Drop this when RUF022 and RUF023 are out of preview
typing-extensions = false
ignore = ["PLR2004", "PLR0911", "PLR0912", "PLR0913", "PLR0915", "PERF203"]
select = ["E", "F", "I", "PL", "UP", "RUF", "PTH", "C4", "B", "PIE", "SIM", "RET", "RSE",
"G", "ISC", "PT", "ASYNC", "TCH", "SLOT", "PERF", "PYI", "FLY", "AIR", "RUF022",
+2 -2
View File
@@ -3928,7 +3928,7 @@ class Bot(TelegramObject, contextlib.AbstractAsyncContextManager["Bot"]):
api_kwargs=api_kwargs,
)
file_path = cast(dict, result).get("file_path")
file_path = cast("dict", result).get("file_path")
if file_path and not is_local_file(file_path):
result["file_path"] = f"{self._base_file_url}/{file_path}"
@@ -4591,7 +4591,7 @@ class Bot(TelegramObject, contextlib.AbstractAsyncContextManager["Bot"]):
# waiting for the server to return and there's no way of knowing the connection had been
# dropped in real time.
result = cast(
list[JSONDict],
"list[JSONDict]",
await self._post(
"getUpdates",
data,
+1 -1
View File
@@ -290,7 +290,7 @@ class TelegramObject:
self._bot = None
# get api_kwargs first because we may need to add entries to it (see try-except below)
api_kwargs = cast(dict[str, object], state.pop("api_kwargs", {}))
api_kwargs = cast("dict[str, object]", state.pop("api_kwargs", {}))
# get _frozen before the loop to avoid setting it to True in the loop
frozen = state.pop("_frozen", False)
+2 -2
View File
@@ -59,7 +59,7 @@ def load_file(
try:
contents = obj.read() # type: ignore[union-attr]
except AttributeError:
return None, cast(Union[bytes, "InputFile", str, Path], obj)
return None, cast("Union[bytes, InputFile, str, Path]", obj)
filename = guess_file_name(obj)
@@ -151,7 +151,7 @@ def parse_file_input( # pylint: disable=too-many-return-statements
if isinstance(file_input, bytes):
return InputFile(file_input, filename=filename, attach=attach)
if hasattr(file_input, "read"):
return InputFile(cast(IO, file_input), filename=filename, attach=attach)
return InputFile(cast("IO", file_input), filename=filename, attach=attach)
if tg_type and isinstance(file_input, tg_type):
return file_input.file_id # type: ignore[attr-defined]
return file_input
+1 -1
View File
@@ -355,7 +355,7 @@ class Application(
self.__create_task_tasks: set[asyncio.Task] = set() # Used for awaiting tasks upon exit
self.__stop_running_marker = asyncio.Event()
async def __aenter__(self: _AppType) -> _AppType: # noqa: PYI019
async def __aenter__(self: _AppType) -> _AppType:
"""|async_context_manager| :meth:`initializes <initialize>` the App.
Returns:
+1 -1
View File
@@ -74,7 +74,7 @@ class BaseUpdateProcessor(AbstractAsyncContextManager["BaseUpdateProcessor"], AB
raise ValueError("`max_concurrent_updates` must be a positive integer!")
self._semaphore = TrackedBoundedSemaphore(self.max_concurrent_updates)
async def __aenter__(self: _BUPT) -> _BUPT: # noqa: PYI019
async def __aenter__(self: _BUPT) -> _BUPT:
"""|async_context_manager| :meth:`initializes <initialize>` the Processor.
Returns:
+1 -1
View File
@@ -347,7 +347,7 @@ class CallbackDataCache:
for row in message.reply_markup.inline_keyboard:
for button in row:
if button.callback_data:
button_data = cast(str, button.callback_data)
button_data = cast("str", button.callback_data)
keyboard_id, callback_data = self.__get_keyboard_uuid_and_button_data(
button_data
)
+1 -1
View File
@@ -145,7 +145,7 @@ class DictPersistence(BasePersistence[dict[Any, Any], dict[Any, Any], dict[Any,
self._callback_data = None
else:
self._callback_data = cast(
CDCData,
"CDCData",
([(one, float(two), three) for one, two, three in data[0]], data[1]),
)
self._callback_data_json = callback_data_json
+1 -1
View File
@@ -253,7 +253,7 @@ class ExtBot(Bot, Generic[RLARGS]):
return
if not isinstance(arbitrary_callback_data, bool):
maxsize = cast(int, arbitrary_callback_data)
maxsize = cast("int", arbitrary_callback_data)
else:
maxsize = 1024
@@ -204,5 +204,5 @@ class CallbackQueryHandler(BaseHandler[Update, CCT, RT]):
:attr:`CallbackContext.matches` as list with one element.
"""
if self.pattern:
check_result = cast(Match, check_result)
check_result = cast("Match", check_result)
context.matches = [check_result]
@@ -118,5 +118,5 @@ class ChosenInlineResultHandler(BaseHandler[Update, CCT, RT]):
:attr:`telegram.ext.CallbackContext.matches`.
"""
if self.pattern:
check_result = cast(Match, check_result)
check_result = cast("Match", check_result)
context.matches = [check_result]
@@ -599,7 +599,7 @@ class ConversationHandler(BaseHandler[Update, CCT, object]):
current_conversations = self._conversations
self._conversations = cast(
TrackingDict[ConversationKey, object],
"TrackingDict[ConversationKey, object]",
TrackingDict(),
)
# In the conversation already processed updates
@@ -924,7 +924,7 @@ class ConversationHandler(BaseHandler[Update, CCT, object]):
:obj:`True` is handled.
"""
job = cast("Job", context.job)
ctxt = cast(_ConversationTimeoutContext, job.data)
ctxt = cast("_ConversationTimeoutContext", job.data)
_LOGGER.debug(
"Conversation timeout was triggered for conversation %s!", ctxt.conversation_key
+1 -1
View File
@@ -139,5 +139,5 @@ class InlineQueryHandler(BaseHandler[Update, CCT, RT]):
:attr:`CallbackContext.matches` as list with one element.
"""
if self.pattern:
check_result = cast(Match, check_result)
check_result = cast("Match", check_result)
context.matches = [check_result]
+1 -1
View File
@@ -237,7 +237,7 @@ class PicklePersistence(BasePersistence[UD, CD, BD]):
self.callback_data: Optional[CDCData] = None
self.conversations: Optional[dict[str, dict[tuple[Union[int, str], ...], object]]] = None
self.context_types: ContextTypes[Any, UD, CD, BD] = cast(
ContextTypes[Any, UD, CD, BD], context_types or ContextTypes()
"ContextTypes[Any, UD, CD, BD]", context_types or ContextTypes()
)
def _load_singlefile(self) -> None:
+1 -1
View File
@@ -124,7 +124,7 @@ class Updater(contextlib.AbstractAsyncContextManager["Updater"]):
self.__polling_task_stop_event: asyncio.Event = asyncio.Event()
self.__polling_cleanup_cb: Optional[Callable[[], Coroutine[Any, Any, None]]] = None
async def __aenter__(self: _UpdaterType) -> _UpdaterType: # noqa: PYI019
async def __aenter__(self: _UpdaterType) -> _UpdaterType:
"""
|async_context_manager| :meth:`initializes <initialize>` the Updater.
+2 -2
View File
@@ -1588,10 +1588,10 @@ class Language(MessageFilter):
def __init__(self, lang: SCT[str]):
if isinstance(lang, str):
lang = cast(str, lang)
lang = cast("str", lang)
self.lang: Sequence[str] = [lang]
else:
lang = cast(list[str], lang)
lang = cast("list[str]", lang)
self.lang = lang
super().__init__(name=f"filters.Language({self.lang})")
-1
View File
@@ -710,7 +710,6 @@ class TestSendMediaGroupWithoutRequest:
self, offline_bot, chat_id, video_file, photo_file, monkeypatch
):
async def make_assertion(method, url, request_data: RequestData, *args, **kwargs):
nonlocal input_video
files = request_data.multipart_data
video_check = files[input_video.media.attach_name] == input_video.media.field_tuple
thumb_check = (
+1 -1
View File
@@ -621,7 +621,7 @@ async def check_defaults_handling(
kwargs_need_default.remove("parse_mode")
defaults_no_custom_defaults = Defaults()
kwargs = {kwarg: "custom_default" for kwarg in inspect.signature(Defaults).parameters}
kwargs = dict.fromkeys(inspect.signature(Defaults).parameters, "custom_default")
kwargs["tzinfo"] = zoneinfo.ZoneInfo("America/New_York")
kwargs["link_preview_options"] = LinkPreviewOptions(
url="custom_default", show_above_text="custom_default"
+1 -2
View File
@@ -16,8 +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/].
"""The integration of persistence into the application is tested in test_basepersistence.
"""
"""The integration of persistence into the application is tested in test_basepersistence."""
import asyncio
import functools
import inspect
-1
View File
@@ -426,7 +426,6 @@ class TestApplicationBuilder:
httpx_request_init = HTTPXRequest.__init__
def init_transport(*args, **kwargs):
nonlocal httpx_request_kwargs
# This is called once for request and once for get_updates_request, so we make
# it a list
httpx_request_kwargs.append(kwargs.copy())
+1 -2
View File
@@ -1438,7 +1438,7 @@ class TestConversationHandler:
context = None
async def start_callback(u, c):
nonlocal context, self
nonlocal context
context = c
return await self.start(u, c)
@@ -1459,7 +1459,6 @@ class TestConversationHandler:
update = Update(update_id=0, message=message)
async def timeout_callback(u, c):
nonlocal update, context
assert u is update
assert c is context