Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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$
Expand All @@ -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
Expand All @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions changes/unreleased/4858.ajt46xDsbfzFqcghJ2rP6g.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
internal = "Bump `pre-commit` Hooks to Latest Versions"
[[pull_requests]]
uid = "4858"
author_uid = "pre-commit-ci"
closes_threads = []
2 changes: 1 addition & 1 deletion src/telegram/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/telegram/_chatfullinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/telegram/_giveaway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions src/telegram/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
1 change: 0 additions & 1 deletion src/telegram/_passport/encryptedpassportelement.py
Original file line number Diff line number Diff line change
@@ -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 <devs@python-telegram-bot.org>
Expand Down
2 changes: 1 addition & 1 deletion src/telegram/_utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions src/telegram/ext/_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()):
Expand Down Expand Up @@ -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__}")
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/telegram/ext/_handlers/conversationhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/telegram/ext/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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:
"""
Expand Down
5 changes: 4 additions & 1 deletion src/telegram/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/_utils/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/ext/_utils/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
3 changes: 1 addition & 2 deletions tests/ext/test_conversationhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import asyncio
import functools
import logging
from copy import copy
from pathlib import Path
from warnings import filterwarnings

Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ext/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_official/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading