mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-05 14:04:55 -04:00
Add types to synapse.util. (#10601)
This commit is contained in:
parent
ceab5a4bfa
commit
524b8ead77
41 changed files with 400 additions and 253 deletions
|
@ -93,7 +93,7 @@ class DeferredCache(Generic[KT, VT]):
|
|||
TreeCache, "MutableMapping[KT, CacheEntry]"
|
||||
] = cache_type()
|
||||
|
||||
def metrics_cb():
|
||||
def metrics_cb() -> None:
|
||||
cache_pending_metric.labels(name).set(len(self._pending_deferred_cache))
|
||||
|
||||
# cache is used for completed results and maps to the result itself, rather than
|
||||
|
@ -113,7 +113,7 @@ class DeferredCache(Generic[KT, VT]):
|
|||
def max_entries(self):
|
||||
return self.cache.max_size
|
||||
|
||||
def check_thread(self):
|
||||
def check_thread(self) -> None:
|
||||
expected_thread = self.thread
|
||||
if expected_thread is None:
|
||||
self.thread = threading.current_thread()
|
||||
|
@ -235,7 +235,7 @@ class DeferredCache(Generic[KT, VT]):
|
|||
|
||||
self._pending_deferred_cache[key] = entry
|
||||
|
||||
def compare_and_pop():
|
||||
def compare_and_pop() -> bool:
|
||||
"""Check if our entry is still the one in _pending_deferred_cache, and
|
||||
if so, pop it.
|
||||
|
||||
|
@ -256,7 +256,7 @@ class DeferredCache(Generic[KT, VT]):
|
|||
|
||||
return False
|
||||
|
||||
def cb(result):
|
||||
def cb(result) -> None:
|
||||
if compare_and_pop():
|
||||
self.cache.set(key, result, entry.callbacks)
|
||||
else:
|
||||
|
@ -268,7 +268,7 @@ class DeferredCache(Generic[KT, VT]):
|
|||
# not have been. Either way, let's double-check now.
|
||||
entry.invalidate()
|
||||
|
||||
def eb(_fail):
|
||||
def eb(_fail) -> None:
|
||||
compare_and_pop()
|
||||
entry.invalidate()
|
||||
|
||||
|
@ -314,7 +314,7 @@ class DeferredCache(Generic[KT, VT]):
|
|||
for entry in iterate_tree_cache_entry(entry):
|
||||
entry.invalidate()
|
||||
|
||||
def invalidate_all(self):
|
||||
def invalidate_all(self) -> None:
|
||||
self.check_thread()
|
||||
self.cache.clear()
|
||||
for entry in self._pending_deferred_cache.values():
|
||||
|
@ -332,7 +332,7 @@ class CacheEntry:
|
|||
self.callbacks = set(callbacks)
|
||||
self.invalidated = False
|
||||
|
||||
def invalidate(self):
|
||||
def invalidate(self) -> None:
|
||||
if not self.invalidated:
|
||||
self.invalidated = True
|
||||
for callback in self.callbacks:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue