Skip to content

Remove black, isort, flake8, and pyupgrade in favor of Ruff #4886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 31, 2025
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
5 changes: 2 additions & 3 deletions .github/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
40 changes: 6 additions & 34 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,13 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.12.2'
rev: 'v0.12.7'
hooks:
- id: ruff
# Run the linter:
- id: ruff-check
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
- 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:
Expand Down Expand Up @@ -66,18 +52,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 .`
5 changes: 5 additions & 0 deletions changes/unreleased/4886.XSHPk83uhDQdYzurbb4xx9.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
internal = "Remove ``black``, ``isort``, ``flake8``, and ``pyupgrade`` in favor of ``ruff``"
[[pull_requests]]
uid = "4886"
author_uid = "harshil21"
closes_threads = []
1 change: 1 addition & 0 deletions docs/auxil/link_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions examples/arbitrarycallbackdatabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions examples/customwebhookbot/djangobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/customwebhookbot/flaskbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/customwebhookbot/quartbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/customwebhookbot/starlettebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/errorhandlerbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/inlinebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/inlinekeyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/inlinekeyboard2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/passportbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions examples/pollbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions examples/rawapibot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/webappbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 0 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions setup.cfg

This file was deleted.

1 change: 1 addition & 0 deletions src/telegram/_birthdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions src/telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_botcommandscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_botdescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_botname.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_business.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_callbackquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/telegram/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_chatadministratorrights.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_chatbackground.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/telegram/_chatboost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_chatfullinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_chatinvitelink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/telegram/_chatjoinrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/telegram/_chatmemberupdated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/telegram/_chatpermissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_checklists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_copytextbutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/telegram/_directmessagepricechanged.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_files/_basemedium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_files/_basethumbedmedium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/telegram/_files/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading
Loading
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