Add PEP-484 annotations to bots/.

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

View File

@ -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

View File

@ -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:

View File

@ -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