Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
get_identity_dict_from_session: Use overload to avoid unnecessary cast.
Mateusz Mandera7b1f90743f6f
diff --git a/corporate/lib/remote_billing_util.py b/corporate/lib/remote_billing_util.pyindex e88220fafe8..01e75be693a 100644--- a/corporate/lib/remote_billing_util.py+++ b/corporate/lib/remote_billing_util.py@@ -1,5 +1,5 @@import logging-from typing import Literal, TypedDict, cast+from typing import Literal, TypedDict, overloadfrom django.http import HttpRequestfrom django.utils.timezone import now as timezone_now@@ -62,6 +62,20 @@ class RemoteBillingIdentityExpiredError(Exception):self.uri_scheme = uri_scheme+@overload+def get_identity_dict_from_session(+ request: HttpRequest,+ *,+ realm_uuid: str | None,+ server_uuid: None,+) -> RemoteBillingIdentityDict | None: ...+@overload+def get_identity_dict_from_session(+ request: HttpRequest,+ *,+ realm_uuid: None,+ server_uuid: str | None,+) -> LegacyServerIdentityDict | None: ...def get_identity_dict_from_session(request: HttpRequest,*,@@ -103,11 +117,8 @@ def get_remote_realm_and_user_from_session(request: HttpRequest,realm_uuid: str | None,) -> tuple[RemoteRealm, RemoteRealmBillingUser]:- # Cannot use isinstance with TypedDicts, to make mypy know- # which of the TypedDicts in the Union this is - so just cast it.- identity_dict = cast(- RemoteBillingIdentityDict | None,- get_identity_dict_from_session(request, realm_uuid=realm_uuid, server_uuid=None),+ identity_dict: RemoteBillingIdentityDict | None = get_identity_dict_from_session(+ request, realm_uuid=realm_uuid, server_uuid=None)if identity_dict is None: