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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11']
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: False
steps:
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
python-version: [3.7]
python-version: [3.11]
os: [ubuntu-latest]
fail-fast: False
steps:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ repos:
- id: pyupgrade
files: ^(telegram|examples|tests|docs)/.*\.py$
args:
- --py37-plus
- --py38-plus
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
Expand Down
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `Abshar <https://github.com/abxhr>`_
- `Alateas <https://github.com/alateas>`_
- `Ales Dokshanin <https://github.com/alesdokshanin>`_
- `Alizia <https://github.com/thefunkycat>`_
- `Ambro17 <https://github.com/Ambro17>`_
- `Andrej Zhilenkov <https://github.com/Andrej730>`_
- `Anton Tagunov <https://github.com/anton-tagunov>`_
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Introduction

This library provides a pure Python, asynchronous interface for the
`Telegram Bot API <https://core.telegram.org/bots/api>`_.
It's compatible with Python versions **3.7+**.
It's compatible with Python versions **3.8+**.

In addition to the pure API implementation, this library features a number of high-level classes to
make the development of bots easy and straightforward. These classes are contained in the
Expand Down
2 changes: 1 addition & 1 deletion README_RAW.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Introduction

This library provides a pure Python, asynchronous interface for the
`Telegram Bot API <https://core.telegram.org/bots/api>`_.
It's compatible with Python versions **3.7+**.
It's compatible with Python versions **3.8+**.

``python-telegram-bot-raw`` is part of the `python-telegram-bot <https://python-telegram-bot.org>`_ ecosystem and provides the pure API functionality extracted from PTB. It therefore does not have independent release schedules, changelogs or documentation.

Expand Down
9 changes: 6 additions & 3 deletions docs/auxil/admonition_inserter.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ def _create_available_in(self) -> dict[type, str]:
break

for line in lines_with_attrs:
line_match = attr_docstr_pattern.match(line)
if not line_match:
if not (line_match := attr_docstr_pattern.match(line)):
continue

target_attr = line_match.group("attr_name")
Expand Down Expand Up @@ -529,7 +528,11 @@ def _resolve_arg(self, arg: Any) -> Iterator[Union[type, None]]:
# For custom generics like telegram.ext._application.Application[~BT, ~CCT, ~UD...].
# This must come before the check for isinstance(type) because GenericAlias can also be
# recognized as type if it belongs to <class 'types.GenericAlias'>.
elif str(type(arg)) in ("<class 'typing._GenericAlias'>", "<class 'types.GenericAlias'>"):
elif str(type(arg)) in (
"<class 'typing._GenericAlias'>",
"<class 'types.GenericAlias'>",
"<class 'typing._LiteralGenericAlias'>",
):
if "telegram" in str(arg):
# get_origin() of telegram.ext._application.Application[~BT, ~CCT, ~UD...]
# will produce <class 'telegram.ext._application.Application'>
Expand Down
6 changes: 4 additions & 2 deletions docs/auxil/sphinx_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ def autodoc_process_bases(app, name, obj, option, bases: list):
bases[idx] = f":class:`{base}`"

# Now convert `telegram._message.Message` to `telegram.Message` etc
match = re.search(pattern=r"(telegram(\.ext|))\.[_\w\.]+", string=base)
if not match or "_utils" in base:
if (
not (match := re.search(pattern=r"(telegram(\.ext|))\.[_\w\.]+", string=base))
or "_utils" in base
):
continue

parts = match.group(0).split(".")
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[tool.black]
line-length = 99
target-version = ['py37', 'py38', 'py39', 'py310', 'py311']
target-version = ['py38', 'py39', 'py310', 'py311']

[tool.isort] # black config
profile = "black"
line_length = 99

[tool.ruff]
line-length = 99
target-version = "py37"
target-version = "py38"
show-fixes = true
ignore = ["PLR2004", "PLR0911", "PLR0912", "PLR0913", "PLR0915"]
select = ["E", "F", "I", "PL", "UP", "RUF", "PTH", "C4", "B", "PIE", "SIM", "RET", "RSE",
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,12 @@ def get_setup_kwargs(raw=False):
"Topic :: Internet",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
python_requires=">=3.7",
python_requires=">=3.8",
)

return kwargs
Expand Down
11 changes: 9 additions & 2 deletions telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@
from telegram._utils.defaultvalue import DEFAULT_NONE, DefaultValue
from telegram._utils.files import is_local_file, parse_file_input
from telegram._utils.logging import get_logger
from telegram._utils.types import DVInput, FileInput, JSONDict, ODVInput, ReplyMarkup
from telegram._utils.types import (
CorrectOptionID,
DVInput,
FileInput,
JSONDict,
ODVInput,
ReplyMarkup,
)
from telegram._utils.warnings import warn
from telegram._utils.warnings_transition import warn_about_thumb_return_thumbnail
from telegram._webhookinfo import WebhookInfo
Expand Down Expand Up @@ -6602,7 +6609,7 @@ async def send_poll(
is_anonymous: Optional[bool] = None,
type: Optional[str] = None, # pylint: disable=redefined-builtin
allows_multiple_answers: Optional[bool] = None,
correct_option_id: Optional[int] = None,
correct_option_id: Optional[CorrectOptionID] = None,
is_closed: Optional[bool] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
Expand Down
10 changes: 5 additions & 5 deletions telegram/_botcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Bot Command."""

from typing import ClassVar, Optional
from typing import Final, Optional

from telegram import constants
from telegram._telegramobject import TelegramObject
Expand Down Expand Up @@ -61,22 +61,22 @@ def __init__(self, command: str, description: str, *, api_kwargs: Optional[JSOND

self._freeze()

MIN_COMMAND: ClassVar[int] = constants.BotCommandLimit.MIN_COMMAND
MIN_COMMAND: Final[int] = constants.BotCommandLimit.MIN_COMMAND
""":const:`telegram.constants.BotCommandLimit.MIN_COMMAND`

.. versionadded:: 20.0
"""
MAX_COMMAND: ClassVar[int] = constants.BotCommandLimit.MAX_COMMAND
MAX_COMMAND: Final[int] = constants.BotCommandLimit.MAX_COMMAND
""":const:`telegram.constants.BotCommandLimit.MAX_COMMAND`

.. versionadded:: 20.0
"""
MIN_DESCRIPTION: ClassVar[int] = constants.BotCommandLimit.MIN_DESCRIPTION
MIN_DESCRIPTION: Final[int] = constants.BotCommandLimit.MIN_DESCRIPTION
""":const:`telegram.constants.BotCommandLimit.MIN_DESCRIPTION`

.. versionadded:: 20.0
"""
MAX_DESCRIPTION: ClassVar[int] = constants.BotCommandLimit.MAX_DESCRIPTION
MAX_DESCRIPTION: Final[int] = constants.BotCommandLimit.MAX_DESCRIPTION
""":const:`telegram.constants.BotCommandLimit.MAX_DESCRIPTION`

.. versionadded:: 20.0
Expand Down
16 changes: 8 additions & 8 deletions telegram/_botcommandscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +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, ClassVar, Dict, Optional, Type, Union
from typing import TYPE_CHECKING, Dict, Final, Optional, Type, Union

from telegram import constants
from telegram._telegramobject import TelegramObject
Expand Down Expand Up @@ -60,19 +60,19 @@ class BotCommandScope(TelegramObject):

__slots__ = ("type",)

DEFAULT: ClassVar[str] = constants.BotCommandScopeType.DEFAULT
DEFAULT: Final[str] = constants.BotCommandScopeType.DEFAULT
""":const:`telegram.constants.BotCommandScopeType.DEFAULT`"""
ALL_PRIVATE_CHATS: ClassVar[str] = constants.BotCommandScopeType.ALL_PRIVATE_CHATS
ALL_PRIVATE_CHATS: Final[str] = constants.BotCommandScopeType.ALL_PRIVATE_CHATS
""":const:`telegram.constants.BotCommandScopeType.ALL_PRIVATE_CHATS`"""
ALL_GROUP_CHATS: ClassVar[str] = constants.BotCommandScopeType.ALL_GROUP_CHATS
ALL_GROUP_CHATS: Final[str] = constants.BotCommandScopeType.ALL_GROUP_CHATS
""":const:`telegram.constants.BotCommandScopeType.ALL_GROUP_CHATS`"""
ALL_CHAT_ADMINISTRATORS: ClassVar[str] = constants.BotCommandScopeType.ALL_CHAT_ADMINISTRATORS
ALL_CHAT_ADMINISTRATORS: Final[str] = constants.BotCommandScopeType.ALL_CHAT_ADMINISTRATORS
""":const:`telegram.constants.BotCommandScopeType.ALL_CHAT_ADMINISTRATORS`"""
CHAT: ClassVar[str] = constants.BotCommandScopeType.CHAT
CHAT: Final[str] = constants.BotCommandScopeType.CHAT
""":const:`telegram.constants.BotCommandScopeType.CHAT`"""
CHAT_ADMINISTRATORS: ClassVar[str] = constants.BotCommandScopeType.CHAT_ADMINISTRATORS
CHAT_ADMINISTRATORS: Final[str] = constants.BotCommandScopeType.CHAT_ADMINISTRATORS
""":const:`telegram.constants.BotCommandScopeType.CHAT_ADMINISTRATORS`"""
CHAT_MEMBER: ClassVar[str] = constants.BotCommandScopeType.CHAT_MEMBER
CHAT_MEMBER: Final[str] = constants.BotCommandScopeType.CHAT_MEMBER
""":const:`telegram.constants.BotCommandScopeType.CHAT_MEMBER`"""

def __init__(self, type: str, *, api_kwargs: Optional[JSONDict] = None):
Expand Down
4 changes: 2 additions & 2 deletions telegram/_botname.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/].
"""This module contains an object that represent a Telegram bots name."""
from typing import ClassVar, Optional
from typing import Final, Optional

from telegram import constants
from telegram._telegramobject import TelegramObject
Expand Down Expand Up @@ -50,5 +50,5 @@ def __init__(self, name: str, *, api_kwargs: Optional[JSONDict] = None):

self._freeze()

MAX_LENGTH: ClassVar[int] = constants.BotNameLimit.MAX_NAME_LENGTH
MAX_LENGTH: Final[int] = constants.BotNameLimit.MAX_NAME_LENGTH
""":const:`telegram.constants.BotNameLimit.MAX_NAME_LENGTH`"""
4 changes: 2 additions & 2 deletions telegram/_callbackquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +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 typing import TYPE_CHECKING, ClassVar, Optional, Sequence, Tuple, Union
from typing import TYPE_CHECKING, Final, Optional, Sequence, Tuple, Union

from telegram import constants
from telegram._files.location import Location
Expand Down Expand Up @@ -771,7 +771,7 @@ async def copy_message(
message_thread_id=message_thread_id,
)

MAX_ANSWER_TEXT_LENGTH: ClassVar[
MAX_ANSWER_TEXT_LENGTH: Final[
int
] = constants.CallbackQueryLimit.ANSWER_CALLBACK_QUERY_TEXT_LENGTH
"""
Expand Down
23 changes: 15 additions & 8 deletions telegram/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""This module contains an object that represents a Telegram Chat."""
from datetime import datetime
from html import escape
from typing import TYPE_CHECKING, ClassVar, Optional, Sequence, Tuple, Union
from typing import TYPE_CHECKING, Final, Optional, Sequence, Tuple, Union

from telegram import constants
from telegram._chatlocation import ChatLocation
Expand All @@ -32,7 +32,14 @@
from telegram._utils import enum
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import DVInput, FileInput, JSONDict, ODVInput, ReplyMarkup
from telegram._utils.types import (
CorrectOptionID,
DVInput,
FileInput,
JSONDict,
ODVInput,
ReplyMarkup,
)
from telegram.helpers import escape_markdown
from telegram.helpers import mention_html as helpers_mention_html
from telegram.helpers import mention_markdown as helpers_mention_markdown
Expand Down Expand Up @@ -303,18 +310,18 @@ class Chat(TelegramObject):
"has_aggressive_anti_spam_enabled",
)

SENDER: ClassVar[str] = constants.ChatType.SENDER
SENDER: Final[str] = constants.ChatType.SENDER
""":const:`telegram.constants.ChatType.SENDER`

.. versionadded:: 13.5
"""
PRIVATE: ClassVar[str] = constants.ChatType.PRIVATE
PRIVATE: Final[str] = constants.ChatType.PRIVATE
""":const:`telegram.constants.ChatType.PRIVATE`"""
GROUP: ClassVar[str] = constants.ChatType.GROUP
GROUP: Final[str] = constants.ChatType.GROUP
""":const:`telegram.constants.ChatType.GROUP`"""
SUPERGROUP: ClassVar[str] = constants.ChatType.SUPERGROUP
SUPERGROUP: Final[str] = constants.ChatType.SUPERGROUP
""":const:`telegram.constants.ChatType.SUPERGROUP`"""
CHANNEL: ClassVar[str] = constants.ChatType.CHANNEL
CHANNEL: Final[str] = constants.ChatType.CHANNEL
""":const:`telegram.constants.ChatType.CHANNEL`"""

def __init__(
Expand Down Expand Up @@ -2201,7 +2208,7 @@ async def send_poll(
is_anonymous: Optional[bool] = None,
type: Optional[str] = None,
allows_multiple_answers: Optional[bool] = None,
correct_option_id: Optional[int] = None,
correct_option_id: Optional[CorrectOptionID] = None,
is_closed: Optional[bool] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
Expand Down
6 changes: 3 additions & 3 deletions telegram/_chatlocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a location to which a chat is connected."""

from typing import TYPE_CHECKING, ClassVar, Optional
from typing import TYPE_CHECKING, Final, Optional

from telegram import constants
from telegram._files.location import Location
Expand Down Expand Up @@ -79,12 +79,12 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatLocation

return super().de_json(data=data, bot=bot)

MIN_ADDRESS: ClassVar[int] = constants.LocationLimit.MIN_CHAT_LOCATION_ADDRESS
MIN_ADDRESS: Final[int] = constants.LocationLimit.MIN_CHAT_LOCATION_ADDRESS
""":const:`telegram.constants.LocationLimit.MIN_CHAT_LOCATION_ADDRESS`

.. versionadded:: 20.0
"""
MAX_ADDRESS: ClassVar[int] = constants.LocationLimit.MAX_CHAT_LOCATION_ADDRESS
MAX_ADDRESS: Final[int] = constants.LocationLimit.MAX_CHAT_LOCATION_ADDRESS
""":const:`telegram.constants.LocationLimit.MAX_CHAT_LOCATION_ADDRESS`

.. versionadded:: 20.0
Expand Down
14 changes: 7 additions & 7 deletions telegram/_chatmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram ChatMember."""
import datetime
from typing import TYPE_CHECKING, ClassVar, Dict, Optional, Type
from typing import TYPE_CHECKING, Dict, Final, Optional, Type

from telegram import constants
from telegram._telegramobject import TelegramObject
Expand Down Expand Up @@ -74,17 +74,17 @@ class ChatMember(TelegramObject):

__slots__ = ("user", "status")

ADMINISTRATOR: ClassVar[str] = constants.ChatMemberStatus.ADMINISTRATOR
ADMINISTRATOR: Final[str] = constants.ChatMemberStatus.ADMINISTRATOR
""":const:`telegram.constants.ChatMemberStatus.ADMINISTRATOR`"""
OWNER: ClassVar[str] = constants.ChatMemberStatus.OWNER
OWNER: Final[str] = constants.ChatMemberStatus.OWNER
""":const:`telegram.constants.ChatMemberStatus.OWNER`"""
BANNED: ClassVar[str] = constants.ChatMemberStatus.BANNED
BANNED: Final[str] = constants.ChatMemberStatus.BANNED
""":const:`telegram.constants.ChatMemberStatus.BANNED`"""
LEFT: ClassVar[str] = constants.ChatMemberStatus.LEFT
LEFT: Final[str] = constants.ChatMemberStatus.LEFT
""":const:`telegram.constants.ChatMemberStatus.LEFT`"""
MEMBER: ClassVar[str] = constants.ChatMemberStatus.MEMBER
MEMBER: Final[str] = constants.ChatMemberStatus.MEMBER
""":const:`telegram.constants.ChatMemberStatus.MEMBER`"""
RESTRICTED: ClassVar[str] = constants.ChatMemberStatus.RESTRICTED
RESTRICTED: Final[str] = constants.ChatMemberStatus.RESTRICTED
""":const:`telegram.constants.ChatMemberStatus.RESTRICTED`"""

def __init__(
Expand Down
Loading