Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

ruff: Fix UP033 Use `@functools.cache`.

Anders Kaseorga82a3eb4d7d7
diff --git a/zerver/lib/export.py b/zerver/lib/export.py
index 45285e845ce..08ecd64b2e7 100644
--- a/zerver/lib/export.py
+++ b/zerver/lib/export.py
@@ -14,7 +14,7 @@ import subprocess
import tempfile
from contextlib import suppress
from datetime import datetime
-from functools import lru_cache
+from functools import cache
from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Set, Tuple, TypedDict
import orjson
@@ -2232,7 +2232,7 @@ def chunkify(lst: List[int], chunk_size: int) -> List[List[int]]:
def export_messages_single_user(
user_profile: UserProfile, *, output_dir: Path, reaction_message_ids: Set[int]
) -> None:
- @lru_cache(maxsize=None)
+ @cache
def get_recipient(recipient_id: int) -> str:
recipient = Recipient.objects.get(id=recipient_id)
diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py
index e43b403b882..85bf6cb06fa 100644
--- a/zerver/lib/push_notifications.py
+++ b/zerver/lib/push_notifications.py
@@ -7,7 +7,7 @@ import logging
import re
from dataclasses import dataclass
from email.headerregistry import Address
-from functools import lru_cache
+from functools import cache
from typing import (
TYPE_CHECKING,
Any,
@@ -162,7 +162,7 @@ def has_apns_credentials() -> bool:
return settings.APNS_TOKEN_KEY_FILE is not None or settings.APNS_CERT_FILE is not None
-@lru_cache(maxsize=None)
+@cache
def get_apns_context() -> Optional[APNsContext]:
# We lazily do this import as part of optimizing Zulip's base
# import time.
diff --git a/zerver/lib/timezone.py b/zerver/lib/timezone.py
index 4b4f3a7b22c..049b8d3fe05 100644
--- a/zerver/lib/timezone.py
+++ b/zerver/lib/timezone.py
@@ -1,10 +1,10 @@
-from functools import lru_cache
+from functools import cache
from typing import Dict
from scripts.lib.zulip_tools import get_tzdata_zi
-@lru_cache(maxsize=None)
+@cache
def get_canonical_timezone_map() -> Dict[str, str]:
canonical = {}
with get_tzdata_zi() as f:
diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.py
index 8ce520bce9f..601b918d728 100644
--- a/zerver/tornado/event_queue.py
+++ b/zerver/tornado/event_queue.py
@@ -9,7 +9,7 @@ import traceback
import uuid
from collections import deque
from contextlib import suppress
-from functools import lru_cache
+from functools import cache
from typing import (
AbstractSet,
Any,
@@ -1110,7 +1110,7 @@ def process_message_event(
recipient_type_name: str = wide_dict["type"]
sending_client: str = wide_dict["client"]
- @lru_cache(maxsize=None)
+ @cache
def get_client_payload(
apply_markdown: bool, client_gravatar: bool, can_access_sender: bool
) -> Dict[str, Any]: