diff --git a/tools/run-mypy b/tools/run-mypy index 0675e6d..dbbfa70 100755 --- a/tools/run-mypy +++ b/tools/run-mypy @@ -49,6 +49,8 @@ force_include = [ "zulip_bots/zulip_bots/bots/help/test_help.py", "zulip_bots/zulip_bots/bots/incrementor/incrementor.py", "zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py", + "zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py", + "zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py", "zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py", "zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py", "zulip_bots/zulip_bots/bots/weather/test_weather.py", diff --git a/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py b/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py index 04450b8..c9248b3 100644 --- a/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py +++ b/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py @@ -1,21 +1,23 @@ import re import requests +from typing import Any, Dict + class LinkShortenerHandler(object): '''A Zulip bot that will shorten URLs ("links") in a conversation using the goo.gl URL shortener. ''' - def usage(self): + def usage(self) -> str: return ( 'Mention the link shortener bot in a conversation and then enter ' 'any URLs you want to shorten in the body of the message. \n\n' '`key` must be set in `link_shortener.conf`.') - def initialize(self, bot_handler): + def initialize(self, bot_handler: Any) -> None: self.config_info = bot_handler.get_config_info('link_shortener') - def handle_message(self, message, bot_handler): + def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None: REGEX_STR = ( '(' '(?:http|https):\/\/' # This allows for the HTTP or HTTPS @@ -58,7 +60,7 @@ class LinkShortenerHandler(object): bot_handler.send_reply(message, final_response) - def shorten_link(self, long_url): + def shorten_link(self, long_url: str) -> str: '''Shortens a link using goo.gl Link Shortener and returns it, or returns an empty string if something goes wrong. diff --git a/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py b/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py index 8cf7a5e..bec7571 100644 --- a/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py +++ b/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py @@ -3,18 +3,18 @@ from zulip_bots.test_lib import StubBotTestCase class TestLinkShortenerBot(StubBotTestCase): bot_name = "link_shortener" - def _test(self, message, response): + def _test(self, message: str, response: str) -> None: with self.mock_config_info({'key': 'qwertyuiop'}): self.verify_reply(message, response) - def test_bot(self): + def test_bot(self) -> None: message = 'Shorten https://www.github.com/zulip/zulip please.' response = 'https://www.github.com/zulip/zulip: https://goo.gl/6uoWKb' with self.mock_http_conversation('test_normal'): self._test(message, response) - def test_bot_empty(self): + def test_bot_empty(self) -> None: message = 'Shorten nothing please.' response = 'No links found. Send "help" to see usage instructions.' @@ -23,7 +23,7 @@ class TestLinkShortenerBot(StubBotTestCase): # requests. self._test(message, response) - def test_bot_help(self): + def test_bot_help(self) -> None: message = 'help' response = ('Mention the link shortener bot in a conversation and then ' 'enter any URLs you want to shorten in the body of the message.')