diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2023-05-24 08:59:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-24 12:59:31 +0000 |
commit | 1f55c04cbca6dc56085896dd980defa26ffe3b5b (patch) | |
tree | dcc51ffeee2c83f78379f58165ef8f3f83c915f0 /synapse/util | |
parent | Fix `@trace` not wrapping some state methods that return coroutines correctly... (diff) | |
download | synapse-1f55c04cbca6dc56085896dd980defa26ffe3b5b.tar.xz |
Improve type hints for cached decorator. (#15658)
The cached decorators always return a Deferred, which was not properly propagated. It was close enough when wrapping coroutines, but failed if a bare function was wrapped.
Diffstat (limited to 'synapse/util')
-rw-r--r-- | synapse/util/caches/descriptors.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/synapse/util/caches/descriptors.py b/synapse/util/caches/descriptors.py index 81df71a0c5..8514a75a1c 100644 --- a/synapse/util/caches/descriptors.py +++ b/synapse/util/caches/descriptors.py @@ -220,7 +220,9 @@ class DeferredCacheDescriptor(_CacheDescriptorBase): self.iterable = iterable self.prune_unread_entries = prune_unread_entries - def __get__(self, obj: Optional[Any], owner: Optional[Type]) -> Callable[..., Any]: + def __get__( + self, obj: Optional[Any], owner: Optional[Type] + ) -> Callable[..., "defer.Deferred[Any]"]: cache: DeferredCache[CacheKey, Any] = DeferredCache( name=self.name, max_entries=self.max_entries, @@ -232,7 +234,7 @@ class DeferredCacheDescriptor(_CacheDescriptorBase): get_cache_key = self.cache_key_builder @functools.wraps(self.orig) - def _wrapped(*args: Any, **kwargs: Any) -> Any: + def _wrapped(*args: Any, **kwargs: Any) -> "defer.Deferred[Any]": # If we're passed a cache_context then we'll want to call its invalidate() # whenever we are invalidated invalidate_callback = kwargs.pop("on_invalidate", None) |