Add PEP-484 type annotations to global dictionaties.

This commit is contained in:
Tim Abbott 2016-01-22 16:55:47 -08:00
parent 77be524dc4
commit b99313545e
6 changed files with 13 additions and 11 deletions

View File

@ -9,7 +9,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from zerver.lib.user_agent import parse_user_agent
user_agents_parsed = defaultdict(int)
user_agents_parsed = defaultdict(int) # type: Dict[str, int]
user_agents_path = os.path.join(os.path.dirname(__file__), "user_agents_unique")
parse_errors = 0
for line in open(user_agents_path).readlines():

View File

@ -296,11 +296,11 @@ class EventQueue(object):
return contents
# maps queue ids to client descriptors
clients = {}
clients = {} # type: Dict[int, ClientDescriptor]
# maps user id to list of client descriptors
user_clients = {}
user_clients = {} # type: Dict[int, List[ClientDescriptor]]
# maps realm id to list of client descriptors with all_public_streams=True
realm_clients_all_streams = {}
realm_clients_all_streams = {} # type: Dict[int, List[ClientDescriptor]]
# list of registered gc hooks.
# each one will be called with a user profile id, queue, and bool

View File

@ -40,7 +40,7 @@ def get_user_profile(session_id):
except (UserProfile.DoesNotExist, KeyError):
return None
connections = dict()
connections = dict() # type: Dict[int, SocketConnection]
def get_connection(id):
return connections.get(id)

View File

@ -36,7 +36,7 @@ MAX_MESSAGE_LENGTH = 10000
# Doing 1000 remote cache requests to get_display_recipient is quite slow,
# so add a local cache as well as the remote cache cache.
per_request_display_recipient_cache = {}
per_request_display_recipient_cache = {} # type: Dict[int, List[Dict[str, Any]]]
def get_display_recipient_by_id(recipient_id, recipient_type, recipient_type_id):
if recipient_id not in per_request_display_recipient_cache:
result = get_display_recipient_remote_cache(recipient_id, recipient_type, recipient_type_id)
@ -253,7 +253,7 @@ def get_realm_filters_cache_key(domain):
return 'all_realm_filters:%s' % (domain,)
# We have a per-process cache to avoid doing 1000 remote cache queries during page load
per_request_realm_filters_cache = {}
per_request_realm_filters_cache = {} # type: Dict[str, List[RealmFilter]]
def realm_filters_for_domain(domain):
domain = domain.lower()
if domain not in per_request_realm_filters_cache:
@ -585,7 +585,7 @@ class Recipient(models.Model):
class Client(models.Model):
name = models.CharField(max_length=30, db_index=True, unique=True)
get_client_cache = {}
get_client_cache = {} # type: Dict[str, Client]
def get_client(name):
if name not in get_client_cache:
result = get_client_remote_cache(name)

View File

@ -42,8 +42,10 @@ class MITNameTest(TestCase):
self.assertTrue(not_mit_mailing_list("sipbexch@mit.edu"))
class S3Test(AuthedTestCase):
test_uris = [] # full URIs in public bucket
test_keys = [] # keys in authed bucket
# full URIs in public bucket
test_uris = [] # type: List[str]
# keys in authed bucket
test_keys = [] # type: List[str]
@slow(2.6, "has to contact external S3 service")
@skip("Need S3 mock")

View File

@ -245,7 +245,7 @@ class Command(BaseCommand):
if options["replay_old_messages"]:
restore_saved_messages()
recipient_hash = {}
recipient_hash = {} # type: Dict[int, Recipient]
def get_recipient_by_id(rid):
if rid in recipient_hash:
return recipient_hash[rid]