confirmation: Fix the type annotation of create_confirmation_link.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li 2022-06-28 15:53:19 -04:00 committed by Tim Abbott
parent 0017f7a025
commit 66dd572563
1 changed files with 4 additions and 12 deletions

View File

@ -4,7 +4,7 @@ __revision__ = "$Id: models.py 28 2009-10-22 15:03:02Z jarek.zgoda $"
import datetime
import secrets
from base64 import b32encode
from typing import List, Mapping, Optional, Protocol, Union
from typing import List, Mapping, Optional, Union
from urllib.parse import urljoin
from django.conf import settings
@ -21,14 +21,6 @@ from zerver.lib.types import UnspecifiedValue
from zerver.models import EmailChangeStatus, MultiuseInvite, PreregistrationUser, Realm, UserProfile
class HasRealmObject(Protocol):
realm: Realm
class OptionalHasRealmObject(Protocol):
realm: Optional[Realm]
class ConfirmationKeyException(Exception):
WRONG_LENGTH = 1
EXPIRED = 2
@ -82,7 +74,7 @@ def get_object_from_key(
def create_confirmation_link(
obj: Union[Realm, HasRealmObject, OptionalHasRealmObject],
obj: ConfirmationObjT,
confirmation_type: int,
*,
validity_in_minutes: Union[Optional[int], UnspecifiedValue] = UnspecifiedValue(),
@ -92,10 +84,10 @@ def create_confirmation_link(
# determined by the confirmation_type - its main purpose is for use
# in tests which may want to have control over the exact expiration time.
key = generate_key()
realm = None
realm: Optional[Realm]
if isinstance(obj, Realm):
realm = obj
elif hasattr(obj, "realm"):
else:
realm = obj.realm
current_time = timezone_now()