From 76507afd3c298f4788db95e54913c76f2952284e Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Sun, 8 Nov 2020 21:30:43 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- aiogram/dispatcher/storage.py | 4 ++-- aiogram/dispatcher/webhook.py | 3 +-- aiogram/types/input_file.py | 11 ++--------- aiogram/types/message_entity.py | 6 +----- tests/test_bot.py | 2 +- 5 files changed, 7 insertions(+), 19 deletions(-) diff --git a/aiogram/dispatcher/storage.py b/aiogram/dispatcher/storage.py index 9a4eac76..1262eed0 100644 --- a/aiogram/dispatcher/storage.py +++ b/aiogram/dispatcher/storage.py @@ -54,9 +54,9 @@ class BaseStorage: if chat is None and user is None: raise ValueError('`user` or `chat` parameter is required but no one is provided!') - if user is None and chat is not None: + if user is None: user = chat - elif user is not None and chat is None: + elif chat is None: chat = user return chat, user diff --git a/aiogram/dispatcher/webhook.py b/aiogram/dispatcher/webhook.py index b6280ed1..52191870 100644 --- a/aiogram/dispatcher/webhook.py +++ b/aiogram/dispatcher/webhook.py @@ -116,8 +116,7 @@ class WebhookRequestHandler(web.View): :return: :class:`aiogram.types.Update` """ data = await self.request.json() - update = types.Update(**data) - return update + return types.Update(**data) async def post(self): """ diff --git a/aiogram/types/input_file.py b/aiogram/types/input_file.py index 3a78c499..c974025a 100644 --- a/aiogram/types/input_file.py +++ b/aiogram/types/input_file.py @@ -41,13 +41,9 @@ class InputFile(base.TelegramObject): self._path = path_or_bytesio if filename is None: filename = os.path.split(path_or_bytesio)[-1] - elif isinstance(path_or_bytesio, io.IOBase): + elif isinstance(path_or_bytesio, (io.IOBase, _WebPipe)): self._path = None self._file = path_or_bytesio - elif isinstance(path_or_bytesio, _WebPipe): - self._path = None - self._file = path_or_bytesio - elif isinstance(path_or_bytesio, Path): self._file = path_or_bytesio.open("rb") self._path = path_or_bytesio.resolve() @@ -174,10 +170,7 @@ class _WebPipe: def name(self): if not self._name: *_, part = self.url.rpartition('/') - if part: - self._name = part - else: - self._name = secrets.token_urlsafe(24) + self._name = part or secrets.token_urlsafe(24) return self._name async def open(self): diff --git a/aiogram/types/message_entity.py b/aiogram/types/message_entity.py index 58705265..f2778ed4 100644 --- a/aiogram/types/message_entity.py +++ b/aiogram/types/message_entity.py @@ -50,11 +50,7 @@ class MessageEntity(base.TelegramObject): if sys.maxunicode == 0xFFFF: return text[self.offset : self.offset + self.length] - if not isinstance(text, bytes): - entity_text = text.encode("utf-16-le") - else: - entity_text = text - + 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] return entity_text.decode("utf-16-le") diff --git a/tests/test_bot.py b/tests/test_bot.py index 45d3a3fa..e80b33d1 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -508,7 +508,7 @@ async def test_get_my_commands(bot: Bot, event_loop): async with FakeTelegram(message_data=commands, loop=event_loop): result = await bot.get_my_commands() assert isinstance(result, list) - assert all([isinstance(command, types.BotCommand) for command in result]) + assert all(isinstance(command, types.BotCommand) for command in result) async def test_edit_message_text_by_bot(bot: Bot, event_loop):