'Refactored by Sourcery'

This commit is contained in:
Sourcery AI 2020-11-08 21:30:43 +00:00
parent c6a43c89c4
commit 76507afd3c
5 changed files with 7 additions and 19 deletions

View file

@ -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

View file

@ -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):
"""

View file

@ -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):

View file

@ -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")

View file

@ -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):