From dd4fe7e099c2c7bdb7e0dd521539e9b8e5cd9be6 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 5 Feb 2016 11:27:19 -0800 Subject: [PATCH] Add PEP-484 annotations to bots/. --- bots/jabber_mirror_backend.py | 7 ++++--- bots/summarize_stream.py | 7 ++++--- bots/zephyr_mirror_backend.py | 10 +++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/bots/jabber_mirror_backend.py b/bots/jabber_mirror_backend.py index 09c07ec..60bec45 100755 --- a/bots/jabber_mirror_backend.py +++ b/bots/jabber_mirror_backend.py @@ -37,6 +37,7 @@ # | other sender| x | | | # public mode +-------------+-----+----+--------+---- # | self sender | | | | +from typing import * import logging import threading @@ -78,11 +79,11 @@ class JabberToZulipBot(ClientXMPP): self.nick = jid.username jid.resource = "zulip" ClientXMPP.__init__(self, jid, password) - self.rooms = set() + self.rooms = set() # type: Set[str] self.rooms_to_join = rooms self.add_event_handler("session_start", self.session_start) self.add_event_handler("message", self.message) - self.zulip = None + self.zulip = None # type: zulip.Client self.use_ipv6 = False self.register_plugin('xep_0045') # Jabber chatrooms @@ -195,7 +196,7 @@ class JabberToZulipBot(ClientXMPP): class ZulipToJabberBot(object): def __init__(self, zulip_client): self.client = zulip_client - self.jabber = None + self.jabber = None # type: JabberToZulipBot def set_jabber_client(self, client): self.jabber = client diff --git a/bots/summarize_stream.py b/bots/summarize_stream.py index af7636f..3b4da8c 100644 --- a/bots/summarize_stream.py +++ b/bots/summarize_stream.py @@ -1,4 +1,5 @@ from __future__ import print_function +from typing import * # This is hacky code to analyze data on our support stream. The main # reusable bits are get_recent_messages and get_words. @@ -50,13 +51,13 @@ def generate_support_stats(): narrow = 'stream:support' count = 2000 msgs = get_recent_messages(client, narrow, count) - msgs_by_topic = collections.defaultdict(list) + msgs_by_topic = collections.defaultdict(list) # type: Dict[str, List[Dict[str, Any]]] for msg in msgs: topic = msg['subject'] msgs_by_topic[topic].append(msg) - word_count = collections.defaultdict(int) - email_count = collections.defaultdict(int) + word_count = collections.defaultdict(int) # type: Dict[str, int] + email_count = collections.defaultdict(int) # type: Dict[str, int] if False: for topic in msgs_by_topic: diff --git a/bots/zephyr_mirror_backend.py b/bots/zephyr_mirror_backend.py index 9fc6953..aac3168 100755 --- a/bots/zephyr_mirror_backend.py +++ b/bots/zephyr_mirror_backend.py @@ -21,6 +21,7 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. from __future__ import absolute_import +from typing import * import sys from six.moves import map @@ -28,7 +29,7 @@ from six.moves import range try: import simplejson except ImportError: - import json as simplejson + import json as simplejson # type: ignore import re import time import subprocess @@ -48,6 +49,8 @@ class States(object): Startup, ZulipToZephyr, ZephyrToZulip, ChildSending = list(range(4)) CURRENT_STATE = States.Startup +logger = None # type: logging.Logger + def to_zulip_username(zephyr_username): if "@" in zephyr_username: (user, realm) = zephyr_username.split("@") @@ -878,6 +881,7 @@ def parse_zephyr_subs(verbose=False): return zephyr_subscriptions def open_logger(): + # type: () -> logging.Logger if options.log_path is not None: log_file = options.log_path elif options.forward_class_messages: @@ -1025,7 +1029,7 @@ if __name__ == "__main__": signal.signal(signal.SIGINT, die_gracefully) - (options, args) = parse_args() + (options, args) = parse_args() # type: Any, List[str] logger = open_logger() configure_logger(logger, "parent") @@ -1113,7 +1117,7 @@ or specify the --api-key-file option.""" % (options.api_key_file,)))) options.session_path = "/var/tmp/%s" % (options.user,) if options.forward_from_zulip: - child_pid = os.fork() + child_pid = os.fork() # type: int if child_pid == 0: CURRENT_STATE = States.ZulipToZephyr # Run the zulip => zephyr mirror in the child