From 4e19a7716d8ecef603b35c7717281773defa1c73 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Sun, 27 May 2018 17:08:39 -0700 Subject: [PATCH] mypy: Avoid 'Any' for message in bots. Also remove a few unnecessary typing imports. --- zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py | 4 ++-- zulip_bots/zulip_bots/bots/helloworld/helloworld.py | 4 ++-- zulip_bots/zulip_bots/bots/idonethis/idonethis.py | 4 ++-- zulip_bots/zulip_bots/bots/mention/mention.py | 4 ++-- zulip_bots/zulip_bots/bots/salesforce/salesforce.py | 3 +-- zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py | 1 - zulip_bots/zulip_bots/bots/trello/trello.py | 4 ++-- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py b/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py index d0e60a6..f3c56c8 100644 --- a/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py +++ b/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py @@ -1,6 +1,6 @@ # See readme.md for instructions on running this code. -from typing import Any, List +from typing import Any, List, Dict import requests class BaremetricsHandler(object): @@ -46,7 +46,7 @@ class BaremetricsHandler(object): Version 1.0 ''' - def handle_message(self, message: Any, bot_handler: Any) -> None: + def handle_message(self, message: Dict[str, Any], bot_handler: Any) -> None: message['content'] = message['content'].strip() if message['content'].lower() == 'help': diff --git a/zulip_bots/zulip_bots/bots/helloworld/helloworld.py b/zulip_bots/zulip_bots/bots/helloworld/helloworld.py index 65d5349..f9d9450 100644 --- a/zulip_bots/zulip_bots/bots/helloworld/helloworld.py +++ b/zulip_bots/zulip_bots/bots/helloworld/helloworld.py @@ -1,6 +1,6 @@ # See readme.md for instructions on running this code. -from typing import Any +from typing import Any, Dict class HelloWorldHandler(object): def usage(self) -> str: @@ -12,7 +12,7 @@ class HelloWorldHandler(object): sophisticated, bots. ''' - def handle_message(self, message: Any, bot_handler: Any) -> None: + def handle_message(self, message: Dict[str, Any], bot_handler: Any) -> None: content = 'beep boop' # type: str bot_handler.send_reply(message, content) diff --git a/zulip_bots/zulip_bots/bots/idonethis/idonethis.py b/zulip_bots/zulip_bots/bots/idonethis/idonethis.py index 54514d9..bec54f7 100644 --- a/zulip_bots/zulip_bots/bots/idonethis/idonethis.py +++ b/zulip_bots/zulip_bots/bots/idonethis/idonethis.py @@ -180,10 +180,10 @@ Below are some of the commands you can use, and what they do. new entry `something` for the product team. ''' + default_team_message - def handle_message(self, message: Any, bot_handler: Any) -> None: + def handle_message(self, message: Dict[str, Any], bot_handler: Any) -> None: bot_handler.send_reply(message, self.get_response(message)) - def get_response(self, message: Any) -> str: + def get_response(self, message: Dict[str, Any]) -> str: message_content = message['content'].strip().split() if message_content == "": return "" diff --git a/zulip_bots/zulip_bots/bots/mention/mention.py b/zulip_bots/zulip_bots/bots/mention/mention.py index a21d986..12bfa98 100644 --- a/zulip_bots/zulip_bots/bots/mention/mention.py +++ b/zulip_bots/zulip_bots/bots/mention/mention.py @@ -1,7 +1,7 @@ # See readme.md for instructions on running this code. import requests -from typing import Any, List +from typing import Any, List, Dict import logging class MentionHandler(object): @@ -34,7 +34,7 @@ class MentionHandler(object): Version 1.00 ''' - def handle_message(self, message: Any, bot_handler: Any) -> None: + def handle_message(self, message: Dict[str, Any], bot_handler: Any) -> None: message['content'] = message['content'].strip() if message['content'].lower() == 'help': diff --git a/zulip_bots/zulip_bots/bots/salesforce/salesforce.py b/zulip_bots/zulip_bots/bots/salesforce/salesforce.py index 94357fe..2024a02 100644 --- a/zulip_bots/zulip_bots/bots/salesforce/salesforce.py +++ b/zulip_bots/zulip_bots/bots/salesforce/salesforce.py @@ -1,6 +1,5 @@ # See readme.md for instructions on running this code. -from typing import Any import simple_salesforce from typing import Dict, Any, List import getpass @@ -165,7 +164,7 @@ class SalesforceHandler(object): except simple_salesforce.exceptions.SalesforceAuthenticationFailed as err: bot_handler.quit('Failed to log in to Salesforce. {} {}'.format(err.code, err.message)) - def handle_message(self, message: Any, bot_handler: Any) -> None: + def handle_message(self, message: Dict[str, Any], bot_handler: Any) -> None: try: bot_response = self.get_salesforce_response(message['content']) bot_handler.send_reply(message, bot_response) diff --git a/zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py b/zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py index f0c1f3f..b287e4b 100644 --- a/zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py +++ b/zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py @@ -2,7 +2,6 @@ import requests import logging import re import urllib -from zulip_bots.lib import Any from typing import Optional, Any, Dict diff --git a/zulip_bots/zulip_bots/bots/trello/trello.py b/zulip_bots/zulip_bots/bots/trello/trello.py index c4db62b..bc285ff 100644 --- a/zulip_bots/zulip_bots/bots/trello/trello.py +++ b/zulip_bots/zulip_bots/bots/trello/trello.py @@ -1,4 +1,4 @@ -from typing import Any, List +from typing import Any, List, Dict import requests @@ -42,7 +42,7 @@ class TrelloHandler(object): Use `list-commands` to get information about the supported commands. ''' - def handle_message(self, message: Any, bot_handler: Any) -> None: + def handle_message(self, message: Dict[str, Any], bot_handler: Any) -> None: content = message['content'].strip() if content == '':