realms: Use modern union syntax for property_types.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2025-01-23 16:10:14 -05:00
committed by Anders Kaseorg
parent 73783f5519
commit f52ec0559c
3 changed files with 9 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
from email.headerregistry import Address from email.headerregistry import Address
from enum import IntEnum from enum import IntEnum
from types import UnionType
from typing import TYPE_CHECKING, Optional, TypedDict from typing import TYPE_CHECKING, Optional, TypedDict
from uuid import uuid4 from uuid import uuid4
@@ -627,7 +628,7 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
enable_guest_user_indicator = models.BooleanField(default=True) enable_guest_user_indicator = models.BooleanField(default=True)
# Define the types of the various automatically managed properties # Define the types of the various automatically managed properties
property_types: dict[str, type | tuple[type, ...]] = dict( property_types: dict[str, type | UnionType] = dict(
allow_edit_history=bool, allow_edit_history=bool,
allow_message_editing=bool, allow_message_editing=bool,
avatar_changes_disabled=bool, avatar_changes_disabled=bool,
@@ -647,13 +648,13 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
inline_image_preview=bool, inline_image_preview=bool,
inline_url_embed_preview=bool, inline_url_embed_preview=bool,
invite_required=bool, invite_required=bool,
jitsi_server_url=(str, type(None)), jitsi_server_url=str | None,
mandatory_topics=bool, mandatory_topics=bool,
message_content_allowed_in_email_notifications=bool, message_content_allowed_in_email_notifications=bool,
message_content_edit_limit_seconds=(int, type(None)), message_content_edit_limit_seconds=int | None,
message_content_delete_limit_seconds=(int, type(None)), message_content_delete_limit_seconds=int | None,
move_messages_between_streams_limit_seconds=(int, type(None)), move_messages_between_streams_limit_seconds=int | None,
move_messages_within_stream_limit_seconds=(int, type(None)), move_messages_within_stream_limit_seconds=int | None,
message_retention_days=int, message_retention_days=int,
name=str, name=str,
name_changes_disabled=bool, name_changes_disabled=bool,

View File

@@ -361,7 +361,7 @@ class UserBaseSettings(models.Model):
web_suggest_update_timezone=bool, web_suggest_update_timezone=bool,
) )
modern_notification_settings: dict[str, Any] = dict( modern_notification_settings = dict(
# Add new notification settings here. # Add new notification settings here.
enable_followed_topic_desktop_notifications=bool, enable_followed_topic_desktop_notifications=bool,
enable_followed_topic_email_notifications=bool, enable_followed_topic_email_notifications=bool,

View File

@@ -942,7 +942,7 @@ class RealmTest(ZulipTestCase):
def test_invalid_integer_attribute_values(self) -> None: def test_invalid_integer_attribute_values(self) -> None:
integer_values = [ integer_values = [
key for key, value in Realm.property_types.items() if value in (int, (int, type(None))) key for key, value in Realm.property_types.items() if value in (int, int | None)
] ]
invalid_values = dict( invalid_values = dict(