diff --git a/confirmation/models.py b/confirmation/models.py index f80002132f..86a6f0afb2 100644 --- a/confirmation/models.py +++ b/confirmation/models.py @@ -22,7 +22,7 @@ from typing import Any, Dict, Optional, Text, Union B16_RE = re.compile('^[a-f0-9]{40}$') def generate_key(): - # type: () -> Text + # type: () -> str return generate_random_token(40) class ConfirmationManager(models.Manager): @@ -47,17 +47,17 @@ class ConfirmationManager(models.Manager): return False def get_link_for_object(self, obj, host): - # type: (Union[ContentType, int], str) -> Text + # type: (Union[ContentType, int], str) -> str key = generate_key() self.create(content_object=obj, date_sent=timezone_now(), confirmation_key=key) return self.get_activation_url(key, host) def get_activation_url(self, confirmation_key, host): - # type: (Text, str) -> Text - return u'%s%s%s' % (settings.EXTERNAL_URI_SCHEME, - host, - reverse(self.url_pattern_name, - kwargs={'confirmation_key': confirmation_key})) + # type: (str, str) -> str + return '%s%s%s' % (settings.EXTERNAL_URI_SCHEME, + host, + reverse(self.url_pattern_name, + kwargs={'confirmation_key': confirmation_key})) class EmailChangeConfirmationManager(ConfirmationManager): url_pattern_name = 'zerver.views.user_settings.confirm_email_change' diff --git a/zerver/lib/email_mirror.py b/zerver/lib/email_mirror.py index e979efd397..4eec493236 100644 --- a/zerver/lib/email_mirror.py +++ b/zerver/lib/email_mirror.py @@ -102,7 +102,7 @@ def get_missed_message_token_from_address(address): return msg_string[2:] def create_missed_message_address(user_profile, message): - # type: (UserProfile, Message) -> Text + # type: (UserProfile, Message) -> str if settings.EMAIL_GATEWAY_PATTERN == '': logging.warning("EMAIL_GATEWAY_PATTERN is an empty string, using " "NOREPLY_EMAIL_ADDRESS in the 'from' field.") diff --git a/zerver/lib/utils.py b/zerver/lib/utils.py index d0289de166..d69176f605 100644 --- a/zerver/lib/utils.py +++ b/zerver/lib/utils.py @@ -116,8 +116,8 @@ def log_statsd_event(name): statsd.incr(event_name) def generate_random_token(length): - # type: (int) -> Text - return base64.b16encode(os.urandom(length // 2)).decode('utf-8').lower() + # type: (int) -> str + return str(base64.b16encode(os.urandom(length // 2)).decode('utf-8').lower()) def mkdir_p(path): # type: (str) -> None diff --git a/zerver/models.py b/zerver/models.py index cf011f7193..0ea1b9ff39 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -863,7 +863,7 @@ class PushDeviceToken(AbstractPushDeviceToken): user = models.ForeignKey(UserProfile, db_index=True, on_delete=CASCADE) # type: UserProfile def generate_email_token_for_stream(): - # type: () -> Text + # type: () -> str return generate_random_token(32) class Stream(ModelReprMixin, models.Model): @@ -875,7 +875,7 @@ class Stream(ModelReprMixin, models.Model): # e-mail length of 254, and our max stream length is 30, so we # have plenty of room for the token. email_token = models.CharField( - max_length=32, default=generate_email_token_for_stream) # type: Text + max_length=32, default=generate_email_token_for_stream) # type: str description = models.CharField(max_length=1024, default=u'') # type: Text date_created = models.DateTimeField(default=timezone_now) # type: datetime.datetime diff --git a/zerver/views/users.py b/zerver/views/users.py index 48836cbd43..88c307cb95 100644 --- a/zerver/views/users.py +++ b/zerver/views/users.py @@ -384,7 +384,7 @@ def create_user_backend(request, user_profile, email=REQ(), password=REQ(), return json_success() def generate_client_id(): - # type: () -> Text + # type: () -> str return generate_random_token(32) def get_profile_backend(request, user_profile):