diff options
author | Sean Quah <8349537+squahtx@users.noreply.github.com> | 2021-11-30 15:39:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-30 15:39:07 +0000 |
commit | 5a0b652d36ae4b6d423498c1f2c82c97a49c6f75 (patch) | |
tree | 16e7f4f015716252e2846ba187e5cece6d7fddbd /synapse/util/caches/deferred_cache.py | |
parent | Remove unnecessary `json.dumps` from `tests.rest.admin` (#11461) (diff) | |
download | synapse-5a0b652d36ae4b6d423498c1f2c82c97a49c6f75.tar.xz |
Eliminate a few `Any`s in `LruCache` type hints (#11453)
Diffstat (limited to 'synapse/util/caches/deferred_cache.py')
-rw-r--r-- | synapse/util/caches/deferred_cache.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/synapse/util/caches/deferred_cache.py b/synapse/util/caches/deferred_cache.py index 3c4cc093af..377c9a282a 100644 --- a/synapse/util/caches/deferred_cache.py +++ b/synapse/util/caches/deferred_cache.py @@ -22,6 +22,7 @@ from typing import ( Iterable, MutableMapping, Optional, + Sized, TypeVar, Union, cast, @@ -104,7 +105,13 @@ class DeferredCache(Generic[KT, VT]): max_size=max_entries, cache_name=name, cache_type=cache_type, - size_callback=(lambda d: len(d) or 1) if iterable else None, + size_callback=( + (lambda d: len(cast(Sized, d)) or 1) + # Argument 1 to "len" has incompatible type "VT"; expected "Sized" + # We trust that `VT` is `Sized` when `iterable` is `True` + if iterable + else None + ), metrics_collection_callback=metrics_cb, apply_cache_factor_from_config=apply_cache_factor_from_config, prune_unread_entries=prune_unread_entries, |