Add PEP-484 annotations to bots/.

This commit is contained in:
Tim Abbott 2016-02-05 11:27:19 -08:00
parent e2e010156e
commit dd4fe7e099
3 changed files with 15 additions and 9 deletions

View file

@ -37,6 +37,7 @@
# | other sender| x | | | # | other sender| x | | |
# public mode +-------------+-----+----+--------+---- # public mode +-------------+-----+----+--------+----
# | self sender | | | | # | self sender | | | |
from typing import *
import logging import logging
import threading import threading
@ -78,11 +79,11 @@ class JabberToZulipBot(ClientXMPP):
self.nick = jid.username self.nick = jid.username
jid.resource = "zulip" jid.resource = "zulip"
ClientXMPP.__init__(self, jid, password) ClientXMPP.__init__(self, jid, password)
self.rooms = set() self.rooms = set() # type: Set[str]
self.rooms_to_join = rooms self.rooms_to_join = rooms
self.add_event_handler("session_start", self.session_start) self.add_event_handler("session_start", self.session_start)
self.add_event_handler("message", self.message) self.add_event_handler("message", self.message)
self.zulip = None self.zulip = None # type: zulip.Client
self.use_ipv6 = False self.use_ipv6 = False
self.register_plugin('xep_0045') # Jabber chatrooms self.register_plugin('xep_0045') # Jabber chatrooms
@ -195,7 +196,7 @@ class JabberToZulipBot(ClientXMPP):
class ZulipToJabberBot(object): class ZulipToJabberBot(object):
def __init__(self, zulip_client): def __init__(self, zulip_client):
self.client = zulip_client self.client = zulip_client
self.jabber = None self.jabber = None # type: JabberToZulipBot
def set_jabber_client(self, client): def set_jabber_client(self, client):
self.jabber = client self.jabber = client

View file

@ -1,4 +1,5 @@
from __future__ import print_function from __future__ import print_function
from typing import *
# This is hacky code to analyze data on our support stream. The main # This is hacky code to analyze data on our support stream. The main
# reusable bits are get_recent_messages and get_words. # reusable bits are get_recent_messages and get_words.
@ -50,13 +51,13 @@ def generate_support_stats():
narrow = 'stream:support' narrow = 'stream:support'
count = 2000 count = 2000
msgs = get_recent_messages(client, narrow, count) 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: for msg in msgs:
topic = msg['subject'] topic = msg['subject']
msgs_by_topic[topic].append(msg) msgs_by_topic[topic].append(msg)
word_count = collections.defaultdict(int) word_count = collections.defaultdict(int) # type: Dict[str, int]
email_count = collections.defaultdict(int) email_count = collections.defaultdict(int) # type: Dict[str, int]
if False: if False:
for topic in msgs_by_topic: for topic in msgs_by_topic:

View file

@ -21,6 +21,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
from __future__ import absolute_import from __future__ import absolute_import
from typing import *
import sys import sys
from six.moves import map from six.moves import map
@ -28,7 +29,7 @@ from six.moves import range
try: try:
import simplejson import simplejson
except ImportError: except ImportError:
import json as simplejson import json as simplejson # type: ignore
import re import re
import time import time
import subprocess import subprocess
@ -48,6 +49,8 @@ class States(object):
Startup, ZulipToZephyr, ZephyrToZulip, ChildSending = list(range(4)) Startup, ZulipToZephyr, ZephyrToZulip, ChildSending = list(range(4))
CURRENT_STATE = States.Startup CURRENT_STATE = States.Startup
logger = None # type: logging.Logger
def to_zulip_username(zephyr_username): def to_zulip_username(zephyr_username):
if "@" in zephyr_username: if "@" in zephyr_username:
(user, realm) = zephyr_username.split("@") (user, realm) = zephyr_username.split("@")
@ -878,6 +881,7 @@ def parse_zephyr_subs(verbose=False):
return zephyr_subscriptions return zephyr_subscriptions
def open_logger(): def open_logger():
# type: () -> logging.Logger
if options.log_path is not None: if options.log_path is not None:
log_file = options.log_path log_file = options.log_path
elif options.forward_class_messages: elif options.forward_class_messages:
@ -1025,7 +1029,7 @@ if __name__ == "__main__":
signal.signal(signal.SIGINT, die_gracefully) signal.signal(signal.SIGINT, die_gracefully)
(options, args) = parse_args() (options, args) = parse_args() # type: Any, List[str]
logger = open_logger() logger = open_logger()
configure_logger(logger, "parent") 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,) options.session_path = "/var/tmp/%s" % (options.user,)
if options.forward_from_zulip: if options.forward_from_zulip:
child_pid = os.fork() child_pid = os.fork() # type: int
if child_pid == 0: if child_pid == 0:
CURRENT_STATE = States.ZulipToZephyr CURRENT_STATE = States.ZulipToZephyr
# Run the zulip => zephyr mirror in the child # Run the zulip => zephyr mirror in the child