From ab9128d93935bd4c769fe87daef5b630fa5f8972 Mon Sep 17 00:00:00 2001 From: fredfishgames Date: Fri, 8 Dec 2017 12:31:42 +0000 Subject: [PATCH] mypy: Add annotations for weather. --- tools/run-mypy | 2 ++ zulip_bots/zulip_bots/bots/weather/test_weather.py | 4 +++- zulip_bots/zulip_bots/bots/weather/weather.py | 14 ++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/run-mypy b/tools/run-mypy index 95ce238..7a83cb6 100755 --- a/tools/run-mypy +++ b/tools/run-mypy @@ -48,6 +48,8 @@ force_include = [ "zulip_bots/zulip_bots/bots/help/test_help.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", + "zulip_bots/zulip_bots/bots/weather/weather.py", ] parser = argparse.ArgumentParser(description="Run mypy on files tracked by git.") diff --git a/zulip_bots/zulip_bots/bots/weather/test_weather.py b/zulip_bots/zulip_bots/bots/weather/test_weather.py index f3342c1..1548fd6 100644 --- a/zulip_bots/zulip_bots/bots/weather/test_weather.py +++ b/zulip_bots/zulip_bots/bots/weather/test_weather.py @@ -5,10 +5,12 @@ from __future__ import print_function from zulip_bots.test_lib import BotTestCase +from typing import Any + class TestWeatherBot(BotTestCase): bot_name = "weather" - def test_bot(self): + def test_bot(self) -> None: # City query bot_response = "Weather in New York, US:\n71.33 F / 21.85 C\nMist" diff --git a/zulip_bots/zulip_bots/bots/weather/weather.py b/zulip_bots/zulip_bots/bots/weather/weather.py index 9225804..a14b2d3 100644 --- a/zulip_bots/zulip_bots/bots/weather/weather.py +++ b/zulip_bots/zulip_bots/bots/weather/weather.py @@ -3,17 +3,19 @@ from __future__ import print_function import requests import json +from typing import Any, Dict + class WeatherHandler(object): - def initialize(self, bot_handler): + def initialize(self, bot_handler: Any) -> None: self.api_key = bot_handler.get_config_info('weather')['key'] self.response_pattern = 'Weather in {}, {}:\n{:.2f} F / {:.2f} C\n{}' - def usage(self): + def usage(self) -> str: return ''' This plugin will give info about weather in a specified city ''' - def handle_message(self, message, bot_handler): + def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None: help_content = ''' This bot returns weather info for specified city. You specify city in the following format: @@ -37,7 +39,7 @@ class WeatherHandler(object): bot_handler.send_reply(message, response) -def format_response(text, city, response_pattern): +def format_response(text: Any, city: str, response_pattern: str) -> str: j = text.json() city = j['name'] country = j['sys']['country'] @@ -48,11 +50,11 @@ def format_response(text, city, response_pattern): return response_pattern.format(city, country, fahrenheit, celsius, description) -def to_celsius(temp_kelvin): +def to_celsius(temp_kelvin: float) -> float: return int(temp_kelvin) - 273.15 -def to_fahrenheit(temp_kelvin): +def to_fahrenheit(temp_kelvin: float) -> float: return int(temp_kelvin) * (9. / 5.) - 459.67 handler_class = WeatherHandler