From b99313545e8b0bdbb0a0b1cbc3f805dbdcaae7da Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 22 Jan 2016 16:55:47 -0800 Subject: [PATCH] Add PEP-484 type annotations to global dictionaties. --- tools/test_user_agent_parsing.py | 2 +- zerver/lib/event_queue.py | 6 +++--- zerver/lib/socket.py | 2 +- zerver/models.py | 6 +++--- zerver/test_external.py | 6 ++++-- zilencer/management/commands/populate_db.py | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tools/test_user_agent_parsing.py b/tools/test_user_agent_parsing.py index 103ac86f2a..78aa1c5acd 100755 --- a/tools/test_user_agent_parsing.py +++ b/tools/test_user_agent_parsing.py @@ -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(): diff --git a/zerver/lib/event_queue.py b/zerver/lib/event_queue.py index 1d60cfd788..b34ce4c62c 100644 --- a/zerver/lib/event_queue.py +++ b/zerver/lib/event_queue.py @@ -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 diff --git a/zerver/lib/socket.py b/zerver/lib/socket.py index d4d6f33f4e..e378bfed35 100644 --- a/zerver/lib/socket.py +++ b/zerver/lib/socket.py @@ -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) diff --git a/zerver/models.py b/zerver/models.py index 3a64d63a1c..83fe9b4ecb 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -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) diff --git a/zerver/test_external.py b/zerver/test_external.py index bc9d9bfb30..e148d6e783 100644 --- a/zerver/test_external.py +++ b/zerver/test_external.py @@ -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") diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py index 2d54cd21e3..70f515ab8a 100644 --- a/zilencer/management/commands/populate_db.py +++ b/zilencer/management/commands/populate_db.py @@ -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]