From b382eacd18729c28f9f94db1a3a8f75a0c60cb8a Mon Sep 17 00:00:00 2001 From: Kai Chen Date: Thu, 7 Dec 2017 16:31:06 -0800 Subject: [PATCH] mypy: Add annotations for define. --- zulip_bots/zulip_bots/bots/define/define.py | 10 ++++++---- zulip_bots/zulip_bots/bots/define/test_define.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/define/define.py b/zulip_bots/zulip_bots/bots/define/define.py index 47d5b1f..ec18548 100644 --- a/zulip_bots/zulip_bots/bots/define/define.py +++ b/zulip_bots/zulip_bots/bots/define/define.py @@ -5,6 +5,8 @@ import requests import html2text import string +from typing import Any, Dict + class DefineHandler(object): ''' This plugin define a word that the user inputs. It @@ -17,19 +19,19 @@ class DefineHandler(object): PHRASE_ERROR_MESSAGE = 'Definitions for phrases are not available.' SYMBOLS_PRESENT_ERROR_MESSAGE = 'Definitions of words with symbols are not possible.' - def usage(self): + def usage(self) -> str: return ''' This plugin will allow users to define a word. Users should preface messages with @mention-bot. ''' - def handle_message(self, message, bot_handler): + def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None: original_content = message['content'].strip() bot_response = self.get_bot_define_response(original_content) bot_handler.send_reply(message, bot_response) - def get_bot_define_response(self, original_content): + def get_bot_define_response(self, original_content: str) -> str: split_content = original_content.split(' ') # If there are more than one word (a phrase) if len(split_content) > 1: @@ -66,7 +68,7 @@ class DefineHandler(object): except Exception as e: response += self.REQUEST_ERROR_MESSAGE - logging.exception(e) + logging.exception("") return response diff --git a/zulip_bots/zulip_bots/bots/define/test_define.py b/zulip_bots/zulip_bots/bots/define/test_define.py index db90c52..479efd5 100755 --- a/zulip_bots/zulip_bots/bots/define/test_define.py +++ b/zulip_bots/zulip_bots/bots/define/test_define.py @@ -5,7 +5,7 @@ from zulip_bots.test_lib import StubBotTestCase class TestDefineBot(StubBotTestCase): bot_name = "define" - def test_bot(self): + def test_bot(self) -> None: # Only one type(noun) of word. bot_response = ("**cat**:\n\n* (**noun**) a small domesticated carnivorous mammal "