From aaf0b42acf4183f801a199668a7a16c0c4e59092 Mon Sep 17 00:00:00 2001 From: Ramzan Bekbulatov Date: Thu, 5 Aug 2021 22:32:30 +0300 Subject: [PATCH] Fix: method Chat.get_member_count usage without argument (#643) * fix: wrong argument passed to get_member_count() * fix: not async .close() for aiohttp.ClientResponse * fix: wrong parameter passed to InputFile * enh: implement all abstract methods for DisabledStorage * ref: style fixes --- aiogram/dispatcher/filters/builtin.py | 2 +- aiogram/dispatcher/storage.py | 20 +++++++++++++++++++- aiogram/types/base.py | 2 +- aiogram/types/bot_command.py | 2 +- aiogram/types/chat.py | 2 +- aiogram/types/input_file.py | 12 ++++++------ aiogram/types/message.py | 8 ++++---- aiogram/types/message_entity.py | 4 ++-- aiogram/types/reply_keyboard.py | 4 +++- aiogram/types/sticker.py | 2 -- aiogram/types/voice_chat_scheduled.py | 1 - 11 files changed, 38 insertions(+), 21 deletions(-) diff --git a/aiogram/dispatcher/filters/builtin.py b/aiogram/dispatcher/filters/builtin.py index 7a21ca3f..ebd38f08 100644 --- a/aiogram/dispatcher/filters/builtin.py +++ b/aiogram/dispatcher/filters/builtin.py @@ -4,7 +4,7 @@ import typing import warnings from contextvars import ContextVar from dataclasses import dataclass, field -from typing import Any, Dict, Iterable, List, Optional, Union +from typing import Any, Dict, Iterable, Optional, Union from babel.support import LazyProxy diff --git a/aiogram/dispatcher/storage.py b/aiogram/dispatcher/storage.py index eb248e34..340b6352 100644 --- a/aiogram/dispatcher/storage.py +++ b/aiogram/dispatcher/storage.py @@ -461,7 +461,6 @@ class DisabledStorage(BaseStorage): """ Empty storage. Use it if you don't want to use Finite-State Machine """ - async def close(self): pass @@ -499,6 +498,25 @@ class DisabledStorage(BaseStorage): data: typing.Dict = None): self._warn() + async def get_bucket(self, *, + chat: typing.Union[str, int, None] = None, + user: typing.Union[str, int, None] = None, + default: typing.Optional[dict] = None) -> typing.Dict: + self._warn() + return {} + + async def set_bucket(self, *, + chat: typing.Union[str, int, None] = None, + user: typing.Union[str, int, None] = None, + bucket: typing.Dict = None): + self._warn() + + async def update_bucket(self, *, + chat: typing.Union[str, int, None] = None, + user: typing.Union[str, int, None] = None, + bucket: typing.Dict = None, **kwargs): + self._warn() + @staticmethod def _warn(): warn(f"You haven’t set any storage yet so no states and no data will be saved. \n" diff --git a/aiogram/types/base.py b/aiogram/types/base.py index 5ef774dd..3f8cda60 100644 --- a/aiogram/types/base.py +++ b/aiogram/types/base.py @@ -78,7 +78,7 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject): Abstract class for telegram objects """ - def __init__(self, conf: typing.Dict[str, typing.Any]=None, **kwargs: typing.Any) -> None: + def __init__(self, conf: typing.Dict[str, typing.Any] = None, **kwargs: typing.Any) -> None: """ Deserialize object diff --git a/aiogram/types/bot_command.py b/aiogram/types/bot_command.py index 39e38e4f..996d1735 100644 --- a/aiogram/types/bot_command.py +++ b/aiogram/types/bot_command.py @@ -12,4 +12,4 @@ class BotCommand(base.TelegramObject): description: base.String = fields.Field() def __init__(self, command: base.String, description: base.String): - super(BotCommand, self).__init__(command=command, description=description) \ No newline at end of file + super(BotCommand, self).__init__(command=command, description=description) diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index c00a3b79..12f6f0fd 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -497,7 +497,7 @@ class Chat(base.TelegramObject): async def get_members_count(self) -> base.Integer: """Renamed to get_member_count.""" - return await self.get_member_count(self.id) + return await self.get_member_count() async def get_member(self, user_id: base.Integer) -> ChatMember: """ diff --git a/aiogram/types/input_file.py b/aiogram/types/input_file.py index c974025a..09ebcfa9 100644 --- a/aiogram/types/input_file.py +++ b/aiogram/types/input_file.py @@ -5,7 +5,7 @@ import logging import os import secrets from pathlib import Path -from typing import Union +from typing import Union, Optional import aiohttp @@ -27,7 +27,7 @@ class InputFile(base.TelegramObject): https://core.telegram.org/bots/api#inputfile """ - def __init__(self, path_or_bytesio: Union[str, io.IOBase, Path], filename=None, conf=None): + def __init__(self, path_or_bytesio: Union[str, io.IOBase, Path, '_WebPipe'], filename=None, conf=None): """ :param path_or_bytesio: @@ -118,7 +118,7 @@ class InputFile(base.TelegramObject): if filename is None: filename = pipe.name - return cls(pipe, filename, chunk_size) + return cls(pipe, filename) def save(self, filename, chunk_size=CHUNK_SIZE): """ @@ -159,8 +159,8 @@ class _WebPipe: self.url = url self.chunk_size = chunk_size - self._session: aiohttp.ClientSession = None - self._response: aiohttp.ClientResponse = None + self._session: Optional[aiohttp.ClientSession] = None + self._response: Optional[aiohttp.ClientResponse] = None self._reader = None self._name = None @@ -182,7 +182,7 @@ class _WebPipe: async def close(self): if self._response and not self._response.closed: - await self._response.close() + self._response.close() if self._session and not self._session.closed: await self._session.close() if self._lock.locked(): diff --git a/aiogram/types/message.py b/aiogram/types/message.py index c95b14b1..8c5d5d3a 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -3039,10 +3039,10 @@ class ContentType(helper.Helper): GROUP_CHAT_CREATED = helper.Item() # group_chat_created PASSPORT_DATA = helper.Item() # passport_data PROXIMITY_ALERT_TRIGGERED = helper.Item() # proximity_alert_triggered - VOICE_CHAT_SCHEDULED = helper.Item() # voice_chat_scheduled - VOICE_CHAT_STARTED = helper.Item() # voice_chat_started - VOICE_CHAT_ENDED = helper.Item() # voice_chat_ended - VOICE_CHAT_PARTICIPANTS_INVITED = helper.Item() # voice_chat_participants_invited + VOICE_CHAT_SCHEDULED = helper.Item() # voice_chat_scheduled + VOICE_CHAT_STARTED = helper.Item() # voice_chat_started + VOICE_CHAT_ENDED = helper.Item() # voice_chat_ended + VOICE_CHAT_PARTICIPANTS_INVITED = helper.Item() # voice_chat_participants_invited UNKNOWN = helper.Item() # unknown ANY = helper.Item() # any diff --git a/aiogram/types/message_entity.py b/aiogram/types/message_entity.py index 9ee98c11..b2aaf425 100644 --- a/aiogram/types/message_entity.py +++ b/aiogram/types/message_entity.py @@ -48,12 +48,12 @@ class MessageEntity(base.TelegramObject): :return: part of text """ if sys.maxunicode == 0xFFFF: - return text[self.offset : self.offset + self.length] + return text[self.offset: self.offset + self.length] entity_text = ( text.encode("utf-16-le") if not isinstance(text, bytes) else text ) - entity_text = entity_text[self.offset * 2 : (self.offset + self.length) * 2] + entity_text = entity_text[self.offset * 2: (self.offset + self.length) * 2] return entity_text.decode("utf-16-le") @deprecated( diff --git a/aiogram/types/reply_keyboard.py b/aiogram/types/reply_keyboard.py index 8455aff6..47efdbbe 100644 --- a/aiogram/types/reply_keyboard.py +++ b/aiogram/types/reply_keyboard.py @@ -129,7 +129,9 @@ class KeyboardButton(base.TelegramObject): class ReplyKeyboardRemove(base.TelegramObject): """ - Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup). + Upon receiving a message with this object, Telegram clients will remove the current custom keyboard + and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. + An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup). https://core.telegram.org/bots/api#replykeyboardremove """ diff --git a/aiogram/types/sticker.py b/aiogram/types/sticker.py index ea222831..afaeb31c 100644 --- a/aiogram/types/sticker.py +++ b/aiogram/types/sticker.py @@ -41,8 +41,6 @@ class Sticker(base.TelegramObject, mixins.Downloadable): Source: https://core.telegram.org/bots/api#deletestickerfromset - :param sticker: File identifier of the sticker - :type sticker: :obj:`base.String` :return: Returns True on success :rtype: :obj:`base.Boolean` """ diff --git a/aiogram/types/voice_chat_scheduled.py b/aiogram/types/voice_chat_scheduled.py index c134eb0f..60655ebf 100644 --- a/aiogram/types/voice_chat_scheduled.py +++ b/aiogram/types/voice_chat_scheduled.py @@ -2,7 +2,6 @@ from datetime import datetime from . import base from . import fields -from .user import User class VoiceChatScheduled(base.TelegramObject):