From 66dd572563bdef85f3bb7bddfad39f293d75a15a Mon Sep 17 00:00:00 2001 From: Zixuan James Li Date: Tue, 28 Jun 2022 15:53:19 -0400 Subject: [PATCH] confirmation: Fix the type annotation of create_confirmation_link. Signed-off-by: Zixuan James Li --- confirmation/models.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/confirmation/models.py b/confirmation/models.py index 87bf2522bb..6193e77d2c 100644 --- a/confirmation/models.py +++ b/confirmation/models.py @@ -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()