Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

test twisted 21.7 #10402

Closed
wants to merge 10 commits into from
Prev Previous commit
Next Next commit
type hints for Deferreds in DeferredCache
  • Loading branch information
richvdh committed Jul 21, 2021
commit a413836cebf03c3fd877eb4a235f41b7657f5505
15 changes: 12 additions & 3 deletions synapse/util/caches/deferred_cache.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,16 @@

import enum
import threading
from typing import Callable, Generic, Iterable, MutableMapping, Optional, TypeVar, Union
from typing import (
Callable,
Generic,
Iterable,
MutableMapping,
Optional,
TypeVar,
Union,
cast,
)

from prometheus_client import Gauge

@@ -166,7 +175,7 @@ def get_immediate(
def set(
self,
key: KT,
value: defer.Deferred,
value: defer.Deferred[VT],
callback: Optional[Callable[[], None]] = None,
) -> defer.Deferred:
"""Adds a new entry to the cache (or updates an existing one).
@@ -214,7 +223,7 @@ def set(
if value.called:
result = value.result
if not isinstance(result, failure.Failure):
self.cache.set(key, result, callbacks)
self.cache.set(key, cast(VT, result), callbacks)
return value

# otherwise, we'll add an entry to the _pending_deferred_cache for now,