From 02cd7b642f86365c329624c96a1f75d428142442 Mon Sep 17 00:00:00 2001 From: Bibo-Joshi Date: Fri, 23 Oct 2020 13:40:02 +0200 Subject: [PATCH] Fix Configuration of Black Formatter (#2158) * Fix Black in pre-commit * Fix black some more --- .pre-commit-config.yaml | 1 + pyproject.toml | 9 +++++++-- telegram/chat.py | 4 ++-- telegram/chatmember.py | 1 + telegram/ext/messagequeue.py | 2 +- telegram/message.py | 3 ++- tests/test_conversationhandler.py | 8 ++++++-- 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5abfb14ab..702c4cad3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,6 +5,7 @@ repos: - id: black args: - --diff + - --check - repo: https://gitlab.com/pycqa/flake8 rev: 3.8.1 hooks: diff --git a/pyproject.toml b/pyproject.toml index 0e944ee55..4de04cce4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,11 @@ [tool.black] line-length = 99 target-version = ['py36'] +skip-string-normalization = true + +# We need to force-exclude the negated include pattern so +# so that pre-commit run --all-files does the correct thing +# see https://github.com/psf/black/issues/1778 +force-exclude = '^(?!(telegram|examples|tests)/).*\.py$' include = '(telegram|examples|tests)/.*\.py$' -exclude = 'telegram/vendor' -skip-string-normalization = true \ No newline at end of file +exclude = 'telegram/vendor' \ No newline at end of file diff --git a/telegram/chat.py b/telegram/chat.py index d39b674f4..2113f176b 100644 --- a/telegram/chat.py +++ b/telegram/chat.py @@ -154,14 +154,14 @@ class Chat(TelegramObject): def is_anonymous_admin(self) -> bool: """:obj:`bool`: Convenience property. Returns :obj:`True`, if this chat is with is the bot representing anonymous admins. This behaviour is undocumented and might be changed - by Telegram. """ + by Telegram.""" return self.id == constants.ANONYMOUS_ADMIN_ID @property def is_service_chat(self) -> bool: """:obj:`bool`: Convenience property. Returns :obj:`True`, if this chat is the Telegram - service chat. This behaviour is undocumented and might be changed by Telegram. """ + service chat. This behaviour is undocumented and might be changed by Telegram.""" return self.id == constants.SERVICE_CHAT_ID diff --git a/telegram/chatmember.py b/telegram/chatmember.py index 59f9c069c..153dfa81a 100644 --- a/telegram/chatmember.py +++ b/telegram/chatmember.py @@ -111,6 +111,7 @@ class ChatMember(TelegramObject): may add web page previews to his messages. """ + ADMINISTRATOR: ClassVar[str] = constants.CHATMEMBER_ADMINISTRATOR """:const:`telegram.constants.CHATMEMBER_ADMINISTRATOR`""" CREATOR: ClassVar[str] = constants.CHATMEMBER_CREATOR diff --git a/telegram/ext/messagequeue.py b/telegram/ext/messagequeue.py index 5335eeec5..d268b18fd 100644 --- a/telegram/ext/messagequeue.py +++ b/telegram/ext/messagequeue.py @@ -305,7 +305,7 @@ def queuedmessage(method: Callable) -> Callable: @functools.wraps(method) def wrapped(self: 'Bot', *args: Any, **kwargs: Any) -> Any: queued = kwargs.pop( - 'queued', self._is_messages_queued_default # type: ignore[attr-defined] + 'queued', self._is_messages_queued_default # type: ignore[attr-defined] ) isgroup = kwargs.pop('isgroup', False) if queued: diff --git a/telegram/message.py b/telegram/message.py index 8fb04c77b..5b39ad547 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -1579,7 +1579,8 @@ class Message(TelegramObject): markdown_text += message_text[last_offset:] else: markdown_text += message_text[last_offset * 2 :].decode( # type: ignore - 'utf-16-le') + 'utf-16-le' + ) return markdown_text diff --git a/tests/test_conversationhandler.py b/tests/test_conversationhandler.py index 06b99e42e..ae7986240 100644 --- a/tests/test_conversationhandler.py +++ b/tests/test_conversationhandler.py @@ -568,7 +568,9 @@ class TestConversationHandler: assert len(handler.conversations) == 0 def test_end_on_first_message_async(self, dp, bot, user1): - start_end_async = (lambda bot, update: dp.run_async(self.start_end, bot, update)) + start_end_async = lambda bot, update: dp.run_async( # noqa: E731 + self.start_end, bot, update + ) handler = ConversationHandler( entry_points=[CommandHandler('start', start_end_async)], states={}, fallbacks=[] @@ -645,7 +647,9 @@ class TestConversationHandler: assert len(handler.conversations) == 0 def test_none_on_first_message_async(self, dp, bot, user1): - start_none_async = (lambda bot, update: dp.run_async(self.start_none, bot, update)) + start_none_async = lambda bot, update: dp.run_async( # noqa: E731 + self.start_none, bot, update + ) handler = ConversationHandler( entry_points=[CommandHandler('start', start_none_async)], states={}, fallbacks=[]