diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2021-12-01 07:28:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-01 07:28:23 -0500 |
commit | f44d729d4ccae61bc0cdd5774acb3233eb5f7c13 (patch) | |
tree | 03ae2faa020831f8116c79d6cddcf2008dce2cf4 /synapse/config/cache.py | |
parent | Register the login redirect endpoint for v3. (#11451) (diff) | |
download | synapse-f44d729d4ccae61bc0cdd5774acb3233eb5f7c13.tar.xz |
Additional type hints for config module. (#11465)
This adds some misc. type hints to helper methods used in the `synapse.config` module.
Diffstat (limited to 'synapse/config/cache.py')
-rw-r--r-- | synapse/config/cache.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/synapse/config/cache.py b/synapse/config/cache.py index f054455534..d9d85f98e1 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -1,4 +1,4 @@ -# Copyright 2019 Matrix.org Foundation C.I.C. +# Copyright 2019-2021 Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ import re import threading from typing import Callable, Dict, Optional +import attr + from synapse.python_dependencies import DependencyException, check_requirements from ._base import Config, ConfigError @@ -34,13 +36,13 @@ _DEFAULT_FACTOR_SIZE = 0.5 _DEFAULT_EVENT_CACHE_SIZE = "10K" +@attr.s(slots=True, auto_attribs=True) class CacheProperties: - def __init__(self): - # The default factor size for all caches - self.default_factor_size = float( - os.environ.get(_CACHE_PREFIX, _DEFAULT_FACTOR_SIZE) - ) - self.resize_all_caches_func = None + # The default factor size for all caches + default_factor_size: float = float( + os.environ.get(_CACHE_PREFIX, _DEFAULT_FACTOR_SIZE) + ) + resize_all_caches_func: Optional[Callable[[], None]] = None properties = CacheProperties() @@ -62,7 +64,7 @@ def _canonicalise_cache_name(cache_name: str) -> str: def add_resizable_cache( cache_name: str, cache_resize_callback: Callable[[float], None] -): +) -> None: """Register a cache that's size can dynamically change Args: @@ -91,7 +93,7 @@ class CacheConfig(Config): _environ = os.environ @staticmethod - def reset(): + def reset() -> None: """Resets the caches to their defaults. Used for tests.""" properties.default_factor_size = float( os.environ.get(_CACHE_PREFIX, _DEFAULT_FACTOR_SIZE) @@ -100,7 +102,7 @@ class CacheConfig(Config): with _CACHES_LOCK: _CACHES.clear() - def generate_config_section(self, **kwargs): + def generate_config_section(self, **kwargs) -> str: return """\ ## Caching ## @@ -162,7 +164,7 @@ class CacheConfig(Config): #sync_response_cache_duration: 2m """ - def read_config(self, config, **kwargs): + def read_config(self, config, **kwargs) -> None: self.event_cache_size = self.parse_size( config.get("event_cache_size", _DEFAULT_EVENT_CACHE_SIZE) ) @@ -232,7 +234,7 @@ class CacheConfig(Config): # needing an instance of Config properties.resize_all_caches_func = self.resize_all_caches - def resize_all_caches(self): + def resize_all_caches(self) -> None: """Ensure all cache sizes are up to date For each cache, run the mapped callback function with either |