mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-03 09:49:21 +01:00
pre-commit
autoupdate (#3537)
Co-authored-by: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com>
This commit is contained in:
parent
23a685335b
commit
007f432ee4
24 changed files with 21 additions and 49 deletions
|
@ -9,7 +9,7 @@ ci:
|
||||||
|
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 22.12.0
|
rev: 23.1.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
args:
|
args:
|
||||||
|
@ -20,7 +20,7 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
- repo: https://github.com/PyCQA/pylint
|
- repo: https://github.com/PyCQA/pylint
|
||||||
rev: v2.15.9
|
rev: v2.16.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: pylint
|
- id: pylint
|
||||||
files: ^(telegram|examples)/.*\.py$
|
files: ^(telegram|examples)/.*\.py$
|
||||||
|
@ -80,7 +80,7 @@ repos:
|
||||||
- --diff
|
- --diff
|
||||||
- --check
|
- --check
|
||||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||||
rev: 'v0.0.222'
|
rev: 'v0.0.243'
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
name: ruff
|
name: ruff
|
||||||
|
|
|
@ -106,7 +106,6 @@ class AdmonitionInserter:
|
||||||
# docs.auxil.sphinx_hooks.autodoc_process_docstring()
|
# docs.auxil.sphinx_hooks.autodoc_process_docstring()
|
||||||
|
|
||||||
for admonition_type in self.ALL_ADMONITION_TYPES:
|
for admonition_type in self.ALL_ADMONITION_TYPES:
|
||||||
|
|
||||||
# If there is no admonition of the given type for the given class or method,
|
# If there is no admonition of the given type for the given class or method,
|
||||||
# continue to the next admonition type, maybe the class/method is listed there.
|
# continue to the next admonition type, maybe the class/method is listed there.
|
||||||
if obj not in self.admonitions[admonition_type]:
|
if obj not in self.admonitions[admonition_type]:
|
||||||
|
@ -258,7 +257,6 @@ class AdmonitionInserter:
|
||||||
|
|
||||||
for cls, method_names in self.METHOD_NAMES_FOR_BOT_AND_APPBUILDER.items():
|
for cls, method_names in self.METHOD_NAMES_FOR_BOT_AND_APPBUILDER.items():
|
||||||
for method_name in method_names:
|
for method_name in method_names:
|
||||||
|
|
||||||
sig = inspect.signature(getattr(cls, method_name))
|
sig = inspect.signature(getattr(cls, method_name))
|
||||||
ret_annot = sig.return_annotation
|
ret_annot = sig.return_annotation
|
||||||
|
|
||||||
|
@ -301,16 +299,13 @@ class AdmonitionInserter:
|
||||||
# inspect methods of all telegram classes for return statements that indicate
|
# inspect methods of all telegram classes for return statements that indicate
|
||||||
# that this given method is a shortcut for a Bot method
|
# that this given method is a shortcut for a Bot method
|
||||||
for class_name, cls in inspect.getmembers(telegram, predicate=inspect.isclass):
|
for class_name, cls in inspect.getmembers(telegram, predicate=inspect.isclass):
|
||||||
|
|
||||||
# no need to inspect Bot's own methods, as Bot can't have shortcuts in Bot
|
# no need to inspect Bot's own methods, as Bot can't have shortcuts in Bot
|
||||||
if cls is telegram.Bot:
|
if cls is telegram.Bot:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for method_name, method in _iter_own_public_methods(cls):
|
for method_name, method in _iter_own_public_methods(cls):
|
||||||
|
|
||||||
# .getsourcelines() returns a tuple. Item [1] is an int
|
# .getsourcelines() returns a tuple. Item [1] is an int
|
||||||
for line in inspect.getsourcelines(method)[0]:
|
for line in inspect.getsourcelines(method)[0]:
|
||||||
|
|
||||||
if not (bot_method_match := bot_method_pattern.search(line)):
|
if not (bot_method_match := bot_method_pattern.search(line)):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -412,7 +407,6 @@ class AdmonitionInserter:
|
||||||
admonition_for_class = {}
|
admonition_for_class = {}
|
||||||
|
|
||||||
for cls, attrs in attrs_or_methods_for_class.items():
|
for cls, attrs in attrs_or_methods_for_class.items():
|
||||||
|
|
||||||
if cls is telegram.ext.ApplicationBuilder:
|
if cls is telegram.ext.ApplicationBuilder:
|
||||||
# ApplicationBuilder is only used in and returned from its own methods,
|
# ApplicationBuilder is only used in and returned from its own methods,
|
||||||
# so its page needs no admonitions.
|
# so its page needs no admonitions.
|
||||||
|
@ -472,7 +466,6 @@ class AdmonitionInserter:
|
||||||
**Modifies dictionary in place.**
|
**Modifies dictionary in place.**
|
||||||
"""
|
"""
|
||||||
for cls in self._resolve_arg(arg):
|
for cls in self._resolve_arg(arg):
|
||||||
|
|
||||||
# When trying to resolve an argument from args or return annotation,
|
# When trying to resolve an argument from args or return annotation,
|
||||||
# the method _resolve_arg returns None if nothing could be resolved.
|
# the method _resolve_arg returns None if nothing could be resolved.
|
||||||
# Also, if class was resolved correctly, "telegram" will definitely be in its str().
|
# Also, if class was resolved correctly, "telegram" will definitely be in its str().
|
||||||
|
@ -549,7 +542,6 @@ class AdmonitionInserter:
|
||||||
# For some reason "InlineQueryResult", "InputMedia" & some others are currently not
|
# For some reason "InlineQueryResult", "InputMedia" & some others are currently not
|
||||||
# recognized as ForwardRefs and are identified as plain strings.
|
# recognized as ForwardRefs and are identified as plain strings.
|
||||||
elif isinstance(arg, str):
|
elif isinstance(arg, str):
|
||||||
|
|
||||||
# args like "ApplicationBuilder[BT, CCT, UD, CD, BD, JQ]" can be recognized as strings.
|
# args like "ApplicationBuilder[BT, CCT, UD, CD, BD, JQ]" can be recognized as strings.
|
||||||
# Remove whatever is in the square brackets because it doesn't need to be parsed.
|
# Remove whatever is in the square brackets because it doesn't need to be parsed.
|
||||||
arg = re.sub(r"\[.+]", "", arg)
|
arg = re.sub(r"\[.+]", "", arg)
|
||||||
|
|
|
@ -391,7 +391,6 @@ class InputMediaVideo(InputMedia):
|
||||||
*,
|
*,
|
||||||
api_kwargs: JSONDict = None,
|
api_kwargs: JSONDict = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
if isinstance(media, Video):
|
if isinstance(media, Video):
|
||||||
width = width if width is not None else media.width
|
width = width if width is not None else media.width
|
||||||
height = height if height is not None else media.height
|
height = height if height is not None else media.height
|
||||||
|
|
|
@ -99,7 +99,6 @@ class InlineQueryResultArticle(InlineQueryResult):
|
||||||
*,
|
*,
|
||||||
api_kwargs: JSONDict = None,
|
api_kwargs: JSONDict = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
# Required
|
# Required
|
||||||
super().__init__(InlineQueryResultType.ARTICLE, id, api_kwargs=api_kwargs)
|
super().__init__(InlineQueryResultType.ARTICLE, id, api_kwargs=api_kwargs)
|
||||||
with self._unfrozen():
|
with self._unfrozen():
|
||||||
|
|
|
@ -113,7 +113,6 @@ class InlineQueryResultAudio(InlineQueryResult):
|
||||||
*,
|
*,
|
||||||
api_kwargs: JSONDict = None,
|
api_kwargs: JSONDict = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
# Required
|
# Required
|
||||||
super().__init__(InlineQueryResultType.AUDIO, id, api_kwargs=api_kwargs)
|
super().__init__(InlineQueryResultType.AUDIO, id, api_kwargs=api_kwargs)
|
||||||
with self._unfrozen():
|
with self._unfrozen():
|
||||||
|
|
|
@ -130,7 +130,6 @@ class InlineQueryResultGif(InlineQueryResult):
|
||||||
*,
|
*,
|
||||||
api_kwargs: JSONDict = None,
|
api_kwargs: JSONDict = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
# Required
|
# Required
|
||||||
super().__init__(InlineQueryResultType.GIF, id, api_kwargs=api_kwargs)
|
super().__init__(InlineQueryResultType.GIF, id, api_kwargs=api_kwargs)
|
||||||
with self._unfrozen():
|
with self._unfrozen():
|
||||||
|
|
|
@ -133,7 +133,6 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
||||||
*,
|
*,
|
||||||
api_kwargs: JSONDict = None,
|
api_kwargs: JSONDict = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
# Required
|
# Required
|
||||||
super().__init__(InlineQueryResultType.MPEG4GIF, id, api_kwargs=api_kwargs)
|
super().__init__(InlineQueryResultType.MPEG4GIF, id, api_kwargs=api_kwargs)
|
||||||
with self._unfrozen():
|
with self._unfrozen():
|
||||||
|
|
|
@ -125,7 +125,6 @@ class InlineQueryResultVenue(InlineQueryResult):
|
||||||
*,
|
*,
|
||||||
api_kwargs: JSONDict = None,
|
api_kwargs: JSONDict = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
# Required
|
# Required
|
||||||
super().__init__(InlineQueryResultType.VENUE, id, api_kwargs=api_kwargs)
|
super().__init__(InlineQueryResultType.VENUE, id, api_kwargs=api_kwargs)
|
||||||
with self._unfrozen():
|
with self._unfrozen():
|
||||||
|
|
|
@ -141,7 +141,6 @@ class InlineQueryResultVideo(InlineQueryResult):
|
||||||
*,
|
*,
|
||||||
api_kwargs: JSONDict = None,
|
api_kwargs: JSONDict = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
# Required
|
# Required
|
||||||
super().__init__(InlineQueryResultType.VIDEO, id, api_kwargs=api_kwargs)
|
super().__init__(InlineQueryResultType.VIDEO, id, api_kwargs=api_kwargs)
|
||||||
with self._unfrozen():
|
with self._unfrozen():
|
||||||
|
|
|
@ -111,7 +111,6 @@ class InlineQueryResultVoice(InlineQueryResult):
|
||||||
*,
|
*,
|
||||||
api_kwargs: JSONDict = None,
|
api_kwargs: JSONDict = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
# Required
|
# Required
|
||||||
super().__init__(InlineQueryResultType.VOICE, id, api_kwargs=api_kwargs)
|
super().__init__(InlineQueryResultType.VOICE, id, api_kwargs=api_kwargs)
|
||||||
with self._unfrozen():
|
with self._unfrozen():
|
||||||
|
|
|
@ -3241,10 +3241,10 @@ class Message(TelegramObject):
|
||||||
html_text = ""
|
html_text = ""
|
||||||
last_offset = 0
|
last_offset = 0
|
||||||
|
|
||||||
sorted_entities = sorted(entities.items(), key=(lambda item: item[0].offset))
|
sorted_entities = sorted(entities.items(), key=lambda item: item[0].offset)
|
||||||
parsed_entities = []
|
parsed_entities = []
|
||||||
|
|
||||||
for (entity, text) in sorted_entities:
|
for entity, text in sorted_entities:
|
||||||
if entity not in parsed_entities:
|
if entity not in parsed_entities:
|
||||||
nested_entities = {
|
nested_entities = {
|
||||||
e: t
|
e: t
|
||||||
|
@ -3426,10 +3426,10 @@ class Message(TelegramObject):
|
||||||
markdown_text = ""
|
markdown_text = ""
|
||||||
last_offset = 0
|
last_offset = 0
|
||||||
|
|
||||||
sorted_entities = sorted(entities.items(), key=(lambda item: item[0].offset))
|
sorted_entities = sorted(entities.items(), key=lambda item: item[0].offset)
|
||||||
parsed_entities = []
|
parsed_entities = []
|
||||||
|
|
||||||
for (entity, text) in sorted_entities:
|
for entity, text in sorted_entities:
|
||||||
if entity not in parsed_entities:
|
if entity not in parsed_entities:
|
||||||
nested_entities = {
|
nested_entities = {
|
||||||
e: t
|
e: t
|
||||||
|
|
|
@ -289,7 +289,6 @@ class TelegramObject:
|
||||||
frozen = state.pop("_frozen", False)
|
frozen = state.pop("_frozen", False)
|
||||||
|
|
||||||
for key, val in state.items():
|
for key, val in state.items():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
setattr(self, key, val)
|
setattr(self, key, val)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -402,7 +401,6 @@ class TelegramObject:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
for key in self._get_attrs_names(include_private=include_private):
|
for key in self._get_attrs_names(include_private=include_private):
|
||||||
|
|
||||||
value = getattr(self, key, None)
|
value = getattr(self, key, None)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
if recursive and hasattr(value, "to_dict"):
|
if recursive and hasattr(value, "to_dict"):
|
||||||
|
|
|
@ -221,12 +221,12 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]):
|
||||||
DefaultValue.get_value(getattr(self, f"{prefix}connection_pool_size")) or 256
|
DefaultValue.get_value(getattr(self, f"{prefix}connection_pool_size")) or 256
|
||||||
)
|
)
|
||||||
|
|
||||||
timeouts = dict(
|
timeouts = {
|
||||||
connect_timeout=getattr(self, f"{prefix}connect_timeout"),
|
"connect_timeout": getattr(self, f"{prefix}connect_timeout"),
|
||||||
read_timeout=getattr(self, f"{prefix}read_timeout"),
|
"read_timeout": getattr(self, f"{prefix}read_timeout"),
|
||||||
write_timeout=getattr(self, f"{prefix}write_timeout"),
|
"write_timeout": getattr(self, f"{prefix}write_timeout"),
|
||||||
pool_timeout=getattr(self, f"{prefix}pool_timeout"),
|
"pool_timeout": getattr(self, f"{prefix}pool_timeout"),
|
||||||
)
|
}
|
||||||
# Get timeouts that were actually set-
|
# Get timeouts that were actually set-
|
||||||
effective_timeouts = {
|
effective_timeouts = {
|
||||||
key: value for key, value in timeouts.items() if not isinstance(value, DefaultValue)
|
key: value for key, value in timeouts.items() if not isinstance(value, DefaultValue)
|
||||||
|
|
|
@ -292,6 +292,7 @@ class ConversationHandler(BaseHandler[Update, CCT]):
|
||||||
WAITING: ClassVar[int] = -3
|
WAITING: ClassVar[int] = -3
|
||||||
""":obj:`int`: Used as a constant to handle state when a conversation is still waiting on the
|
""":obj:`int`: Used as a constant to handle state when a conversation is still waiting on the
|
||||||
previous :attr:`block=False <block>` handler to finish."""
|
previous :attr:`block=False <block>` handler to finish."""
|
||||||
|
|
||||||
# pylint: disable=super-init-not-called
|
# pylint: disable=super-init-not-called
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -80,7 +80,6 @@ class MessageHandler(BaseHandler[Update, CCT]):
|
||||||
callback: HandlerCallback[Update, CCT, RT],
|
callback: HandlerCallback[Update, CCT, RT],
|
||||||
block: DVType[bool] = DEFAULT_TRUE,
|
block: DVType[bool] = DEFAULT_TRUE,
|
||||||
):
|
):
|
||||||
|
|
||||||
super().__init__(callback, block=block)
|
super().__init__(callback, block=block)
|
||||||
self.filters: filters_module.BaseFilter = (
|
self.filters: filters_module.BaseFilter = (
|
||||||
filters if filters is not None else filters_module.ALL
|
filters if filters is not None else filters_module.ALL
|
||||||
|
|
|
@ -130,7 +130,6 @@ class PrefixHandler(BaseHandler[Update, CCT]):
|
||||||
filters: filters_module.BaseFilter = None,
|
filters: filters_module.BaseFilter = None,
|
||||||
block: DVType[bool] = DEFAULT_TRUE,
|
block: DVType[bool] = DEFAULT_TRUE,
|
||||||
):
|
):
|
||||||
|
|
||||||
super().__init__(callback=callback, block=block)
|
super().__init__(callback=callback, block=block)
|
||||||
|
|
||||||
if isinstance(prefix, str):
|
if isinstance(prefix, str):
|
||||||
|
|
|
@ -301,7 +301,6 @@ class Updater(AsyncContextManager["Updater"]):
|
||||||
ready: asyncio.Event,
|
ready: asyncio.Event,
|
||||||
error_callback: Optional[Callable[[TelegramError], None]],
|
error_callback: Optional[Callable[[TelegramError], None]],
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
self._logger.debug("Updater started (polling)")
|
self._logger.debug("Updater started (polling)")
|
||||||
|
|
||||||
# the bootstrapping phase does two things:
|
# the bootstrapping phase does two things:
|
||||||
|
|
|
@ -117,13 +117,13 @@ class HTTPXRequest(BaseRequest):
|
||||||
|
|
||||||
http1 = http_version == "1.1"
|
http1 = http_version == "1.1"
|
||||||
|
|
||||||
self._client_kwargs = dict(
|
self._client_kwargs = {
|
||||||
timeout=timeout,
|
"timeout": timeout,
|
||||||
proxies=proxy_url,
|
"proxies": proxy_url,
|
||||||
limits=limits,
|
"limits": limits,
|
||||||
http1=http1,
|
"http1": http1,
|
||||||
http2=not http1,
|
"http2": not http1,
|
||||||
)
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._client = self._build_client()
|
self._client = self._build_client()
|
||||||
|
|
|
@ -45,7 +45,6 @@ def invite_link(creator):
|
||||||
|
|
||||||
|
|
||||||
class TestChatInviteLink:
|
class TestChatInviteLink:
|
||||||
|
|
||||||
link = "thisialink"
|
link = "thisialink"
|
||||||
creates_join_request = False
|
creates_join_request = False
|
||||||
primary = True
|
primary = True
|
||||||
|
|
|
@ -201,7 +201,6 @@ class TestChatPermissions:
|
||||||
assert f != t
|
assert f != t
|
||||||
|
|
||||||
def test_equality_warning(self, recwarn, chat_permissions):
|
def test_equality_warning(self, recwarn, chat_permissions):
|
||||||
|
|
||||||
recwarn.clear()
|
recwarn.clear()
|
||||||
assert chat_permissions == chat_permissions
|
assert chat_permissions == chat_permissions
|
||||||
|
|
||||||
|
|
|
@ -2053,7 +2053,6 @@ class TestConversationHandler:
|
||||||
await app.stop()
|
await app.stop()
|
||||||
|
|
||||||
async def test_no_timeout_on_end(self, app, user1):
|
async def test_no_timeout_on_end(self, app, user1):
|
||||||
|
|
||||||
conv_handler = ConversationHandler(
|
conv_handler = ConversationHandler(
|
||||||
entry_points=[MessageHandler(filters.ALL, callback=self.start_end)],
|
entry_points=[MessageHandler(filters.ALL, callback=self.start_end)],
|
||||||
states={ConversationHandler.TIMEOUT: [TypeHandler(Update, self.passout2)]},
|
states={ConversationHandler.TIMEOUT: [TypeHandler(Update, self.passout2)]},
|
||||||
|
@ -2116,7 +2115,6 @@ class TestConversationHandler:
|
||||||
async def test_blocking_resolution_order(
|
async def test_blocking_resolution_order(
|
||||||
self, bot, default_block, ch_block, handler_block, ext_bot
|
self, bot, default_block, ch_block, handler_block, ext_bot
|
||||||
):
|
):
|
||||||
|
|
||||||
event = asyncio.Event()
|
event = asyncio.Event()
|
||||||
|
|
||||||
async def callback(_, __):
|
async def callback(_, __):
|
||||||
|
|
|
@ -131,7 +131,6 @@ class TestKeyboardButton:
|
||||||
assert hash(a) == hash(f)
|
assert hash(a) == hash(f)
|
||||||
|
|
||||||
def test_equality_warning(self, recwarn, keyboard_button):
|
def test_equality_warning(self, recwarn, keyboard_button):
|
||||||
|
|
||||||
recwarn.clear()
|
recwarn.clear()
|
||||||
assert keyboard_button == keyboard_button
|
assert keyboard_button == keyboard_button
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,6 @@ class TestAIORateLimiter:
|
||||||
|
|
||||||
@pytest.mark.parametrize("max_retries", [0, 1, 4])
|
@pytest.mark.parametrize("max_retries", [0, 1, 4])
|
||||||
async def test_max_retries(self, bot, max_retries):
|
async def test_max_retries(self, bot, max_retries):
|
||||||
|
|
||||||
bot = ExtBot(
|
bot = ExtBot(
|
||||||
token=bot.token,
|
token=bot.token,
|
||||||
request=self.CountRequest(retry_after=1),
|
request=self.CountRequest(retry_after=1),
|
||||||
|
|
|
@ -480,7 +480,6 @@ class TestHTTPXRequest:
|
||||||
write_timeout=default_timeouts.write,
|
write_timeout=default_timeouts.write,
|
||||||
pool_timeout=default_timeouts.pool,
|
pool_timeout=default_timeouts.pool,
|
||||||
) as httpx_request:
|
) as httpx_request:
|
||||||
|
|
||||||
monkeypatch.setattr(httpx.AsyncClient, "request", make_assertion)
|
monkeypatch.setattr(httpx.AsyncClient, "request", make_assertion)
|
||||||
await httpx_request.do_request(method="GET", url="URL")
|
await httpx_request.do_request(method="GET", url="URL")
|
||||||
|
|
||||||
|
@ -500,7 +499,6 @@ class TestHTTPXRequest:
|
||||||
write_timeout=default_timeouts.write,
|
write_timeout=default_timeouts.write,
|
||||||
pool_timeout=default_timeouts.pool,
|
pool_timeout=default_timeouts.pool,
|
||||||
) as httpx_request:
|
) as httpx_request:
|
||||||
|
|
||||||
monkeypatch.setattr(httpx.AsyncClient, "request", make_assertion)
|
monkeypatch.setattr(httpx.AsyncClient, "request", make_assertion)
|
||||||
await httpx_request.do_request(
|
await httpx_request.do_request(
|
||||||
method="GET",
|
method="GET",
|
||||||
|
|
Loading…
Reference in a new issue