mypy: zulip_bots: Fix errors in zulip_bots/lib.py.

This commit is contained in:
Alena Volkova 2017-10-10 02:23:01 -04:00
parent ad050fc806
commit 3a20dee621
2 changed files with 7 additions and 8 deletions

View file

@ -22,7 +22,6 @@ exclude = """
zulip/integrations/perforce/git_p4.py zulip/integrations/perforce/git_p4.py
zulip_bots/zulip_bots/bots zulip_bots/zulip_bots/bots
zulip_bots/zulip_bots/lib.py
zulip_bots/zulip_bots/provision.py zulip_bots/zulip_bots/provision.py
zulip_bots/zulip_bots/run.py zulip_bots/zulip_bots/run.py
zulip_bots/zulip_bots/test_lib.py zulip_bots/zulip_bots/test_lib.py

View file

@ -14,7 +14,7 @@ from contextlib import contextmanager
if False: if False:
from mypy_extensions import NoReturn from mypy_extensions import NoReturn
from typing import Any, Optional, List, Dict from typing import Any, Optional, List, Dict, IO, Text
from types import ModuleType from types import ModuleType
from zulip import Client from zulip import Client
@ -64,7 +64,7 @@ class StateHandler(object):
self.state_[key] = self.marshal(value) self.state_[key] = self.marshal(value)
def get(self, key): def get(self, key):
# type: () -> Text # type: (Text) -> Text
return self.demarshal(self.state_[key]) return self.demarshal(self.state_[key])
def contains(self, key): def contains(self, key):
@ -73,7 +73,7 @@ class StateHandler(object):
class ExternalBotHandler(object): class ExternalBotHandler(object):
def __init__(self, client, root_dir): def __init__(self, client, root_dir):
# type: (Client, string) -> None # type: (Client, str) -> None
# Only expose a subset of our Client's functionality # Only expose a subset of our Client's functionality
user_profile = client.get_profile() user_profile = client.get_profile()
self._rate_limit = RateLimit(20, 5) self._rate_limit = RateLimit(20, 5)
@ -134,7 +134,7 @@ class ExternalBotHandler(object):
return dict(config.items(section)) return dict(config.items(section))
def open(self, filepath): def open(self, filepath):
# type: (str) -> None # type: (str) -> IO[str]
filepath = os.path.normpath(filepath) filepath = os.path.normpath(filepath)
abs_filepath = os.path.join(self._root_dir, filepath) abs_filepath = os.path.join(self._root_dir, filepath)
if abs_filepath.startswith(self._root_dir): if abs_filepath.startswith(self._root_dir):
@ -170,7 +170,7 @@ def is_private_message_from_another_user(message_dict, current_user_id):
return False return False
def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name): def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):
# type: (Any, bool, str) -> Any # type: (Any, bool, str, str) -> Any
# #
# lib_module is of type Any, since it can contain any bot's # lib_module is of type Any, since it can contain any bot's
# handler class. Eventually, we want bot's handler classes to # handler class. Eventually, we want bot's handler classes to
@ -200,7 +200,7 @@ def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):
print(message_handler.usage()) print(message_handler.usage())
def handle_message(message, flags): def handle_message(message, flags):
# type: (Dict[str, Any]) -> None # type: (Dict[str, Any], List[str]) -> None
logging.info('waiting for next message') logging.info('waiting for next message')
# `mentioned` will be in `flags` if the bot is mentioned at ANY position # `mentioned` will be in `flags` if the bot is mentioned at ANY position
@ -227,7 +227,7 @@ def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):
logging.info('starting message handling...') logging.info('starting message handling...')
def event_callback(event): def event_callback(event):
# type: (Dict[str, str]) -> None # type: (Dict[str, Any]) -> None
if event['type'] == 'message': if event['type'] == 'message':
handle_message(event['message'], event['flags']) handle_message(event['message'], event['flags'])