zerver/lib/bulk_create.py: Fix string annotations.

Change string type from `str` to `text_type` where required.
Also fix clashing annotations.
This commit is contained in:
Eklavya Sharma 2016-06-13 10:08:14 +05:30
parent c654c4032d
commit d169cc5376
3 changed files with 9 additions and 9 deletions

View File

@ -8,7 +8,7 @@ from zerver.models import Realm, Stream, UserProfile, Huddle, \
from zerver.lib.create_user import create_user_profile from zerver.lib.create_user import create_user_profile
def bulk_create_realms(realm_list): def bulk_create_realms(realm_list):
# type: (Iterable[str]) -> None # type: (Iterable[text_type]) -> None
existing_realms = set(r.domain for r in Realm.objects.select_related().all()) existing_realms = set(r.domain for r in Realm.objects.select_related().all())
realms_to_create = [] realms_to_create = []
@ -19,7 +19,7 @@ def bulk_create_realms(realm_list):
Realm.objects.bulk_create(realms_to_create) Realm.objects.bulk_create(realms_to_create)
def bulk_create_users(realms, users_raw, bot_type=None): def bulk_create_users(realms, users_raw, bot_type=None):
# type: (Mapping[str, Realm], Set[Tuple[str, text_type, text_type, bool]], Optional[int]) -> None # type: (Mapping[text_type, Realm], Set[Tuple[text_type, text_type, text_type, bool]], Optional[int]) -> None
""" """
Creates and saves a UserProfile with the given email. Creates and saves a UserProfile with the given email.
Has some code based off of UserManage.create_user, but doesn't .save() Has some code based off of UserManage.create_user, but doesn't .save()
@ -36,7 +36,7 @@ def bulk_create_users(realms, users_raw, bot_type=None):
# Now create user_profiles # Now create user_profiles
profiles_to_create = [] profiles_to_create = []
for (email, full_name, short_name, active) in users: for (email, full_name, short_name, active) in users:
domain = str(resolve_email_to_domain(email)) domain = resolve_email_to_domain(email)
profile = create_user_profile(realms[domain], email, profile = create_user_profile(realms[domain], email,
initial_password(email), active, bot_type, initial_password(email), active, bot_type,
full_name, short_name, None, False) full_name, short_name, None, False)
@ -67,7 +67,7 @@ def bulk_create_users(realms, users_raw, bot_type=None):
Subscription.objects.bulk_create(subscriptions_to_create) Subscription.objects.bulk_create(subscriptions_to_create)
def bulk_create_streams(realms, stream_list): def bulk_create_streams(realms, stream_list):
# type: (Mapping[str, Realm], Iterable[Tuple[str, text_type]]) -> None # type: (Mapping[text_type, Realm], Iterable[Tuple[text_type, text_type]]) -> None
existing_streams = set((stream.realm.domain, stream.name.lower()) existing_streams = set((stream.realm.domain, stream.name.lower())
for stream in Stream.objects.select_related().all()) for stream in Stream.objects.select_related().all())
streams_to_create = [] streams_to_create = []
@ -84,7 +84,7 @@ def bulk_create_streams(realms, stream_list):
Recipient.objects.bulk_create(recipients_to_create) Recipient.objects.bulk_create(recipients_to_create)
def bulk_create_clients(client_list): def bulk_create_clients(client_list):
# type: (Iterable[str]) -> None # type: (Iterable[text_type]) -> None
existing_clients = set(client.name for client in Client.objects.select_related().all()) existing_clients = set(client.name for client in Client.objects.select_related().all())
clients_to_create = [] clients_to_create = []
@ -95,7 +95,7 @@ def bulk_create_clients(client_list):
Client.objects.bulk_create(clients_to_create) Client.objects.bulk_create(clients_to_create)
def bulk_create_huddles(users, huddle_user_list): def bulk_create_huddles(users, huddle_user_list):
# type: (Dict[str, UserProfile], Iterable[Tuple[Any, ...]]) -> None # type: (Dict[text_type, UserProfile], Iterable[Iterable[text_type]]) -> None
huddles = {} huddles = {}
huddles_by_id = {} huddles_by_id = {}
huddle_set = set() huddle_set = set()

View File

@ -17,7 +17,7 @@ from six import text_type
settings.TORNADO_SERVER = None settings.TORNADO_SERVER = None
def create_users(name_list, bot_type=None): def create_users(name_list, bot_type=None):
# type: (Iterable[Tuple[text_type, str]], int) -> None # type: (Iterable[Tuple[text_type, text_type]], int) -> None
realms = {} realms = {}
for realm in Realm.objects.all(): for realm in Realm.objects.all():
realms[realm.domain] = realm realms[realm.domain] = realm

View File

@ -37,7 +37,7 @@ from typing import Any, Dict, List, IO, Iterable, Mapping, Set, Tuple
settings.TORNADO_SERVER = None settings.TORNADO_SERVER = None
def create_users(realms, name_list, bot_type=None): def create_users(realms, name_list, bot_type=None):
# type: (Mapping[str, Realm], Iterable[Tuple[text_type, str]], int) -> None # type: (Mapping[text_type, Realm], Iterable[Tuple[text_type, text_type]], int) -> None
user_set = set() user_set = set()
for full_name, email in name_list: for full_name, email in name_list:
short_name = email_to_username(email) short_name = email_to_username(email)
@ -45,7 +45,7 @@ def create_users(realms, name_list, bot_type=None):
bulk_create_users(realms, user_set, bot_type) bulk_create_users(realms, user_set, bot_type)
def create_streams(realms, realm, stream_list): def create_streams(realms, realm, stream_list):
# type: (Mapping[str, Realm], Realm, Iterable[str]) -> None # type: (Mapping[text_type, Realm], Realm, Iterable[text_type]) -> None
stream_set = set() stream_set = set()
for stream_name in stream_list: for stream_name in stream_list:
stream_set.add((realm.domain, stream_name)) stream_set.add((realm.domain, stream_name))