Make Bot.delete_my_commands a Coroutine Function (#3136)

This commit is contained in:
Bibo-Joshi 2022-07-04 19:33:45 +02:00 committed by GitHub
parent 1f0f6a8d3d
commit 2d6459b290
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View file

@ -7345,7 +7345,7 @@ class Bot(TelegramObject, AbstractAsyncContextManager):
return result # type: ignore[return-value]
@_log
def delete_my_commands(
async def delete_my_commands(
self,
scope: BotCommandScope = None,
language_code: str = None,
@ -7402,7 +7402,7 @@ class Bot(TelegramObject, AbstractAsyncContextManager):
if language_code:
data["language_code"] = language_code
result = self._post(
result = await self._post(
"deleteMyCommands",
data,
read_timeout=read_timeout,

View file

@ -2944,3 +2944,23 @@ class TestBot:
if not camel_case_function:
not_available_camelcase_functions.append(function_name)
assert not_available_camelcase_functions == []
def test_coroutine_functions(self):
"""Check that all bot methods are defined as async def ..."""
non_coroutine_functions = set()
for attr_name, attribute in Bot.__dict__.items():
# not islower() skips the camelcase aliases
if not callable(attribute) or attr_name.startswith("_") or not attr_name.islower():
continue
# unfortunately `inspect.iscoroutinefunction` doesn't do the trick directly,
# as the @_log decorator interferes
source = "".join(inspect.getsourcelines(attribute)[0])
if (
"pool_timeout: ODVInput[float]" in source
and f"async def {attr_name}" not in source
):
non_coroutine_functions.add(attr_name)
assert non_coroutine_functions == set(), (
"The following methods should be defined as coroutine functions: "
f"{','.join(non_coroutine_functions)} "
)