Browse Source

ref(typing): stronger typing for utils/redis (#65894)

Enables stronger typing for `sentry/utils/redis.py`
Yagiz Nizipli 1 year ago
parent
commit
e78a54c954
2 changed files with 5 additions and 4 deletions
  1. 1 0
      pyproject.toml
  2. 4 4
      src/sentry/utils/redis.py

+ 1 - 0
pyproject.toml

@@ -628,6 +628,7 @@ disable_error_code = [
 # beginning: stronger typing
 [[tool.mypy.overrides]]
 module = [
+  "sentry.utils.redis",
   "src.sentry.tasks.on_demand_metrics",
   "src.sentry.relay.config.metric_extraction",
   "src.sentry.snuba.metrics.extraction",

+ 4 - 4
src/sentry/utils/redis.py

@@ -38,7 +38,7 @@ _pool_cache: dict[str, ConnectionPool] = {}
 _pool_lock = Lock()
 
 
-def _shared_pool(**opts: dict[str, Any]) -> ConnectionPool:
+def _shared_pool(**opts: Any) -> ConnectionPool:
     if "host" in opts:
         key = "{}:{}/{}".format(opts["host"], opts["port"], opts["db"])
     else:
@@ -66,7 +66,7 @@ class _RBCluster:
         self,
         decode_responses: bool | None = None,
         hosts: list[dict[int, Any]] | dict[int, Any] | None = None,
-        **config,
+        **config: Any,
     ) -> functools.partial:
         if not decode_responses:
             raise NotImplementedError("decode_responses=False mode is not implemented for `rb`")
@@ -77,7 +77,7 @@ class _RBCluster:
         hosts = {k: v for k, v in enumerate(hosts)} if isinstance(hosts, list) else hosts
         config["hosts"] = hosts
 
-        pool_options = config.pop("client_args", {})
+        pool_options: dict[str, Any] = config.pop("client_args", {})
         pool_options = {**_REDIS_DEFAULT_CLIENT_ARGS, **pool_options}
         config["pool_options"] = pool_options
 
@@ -103,7 +103,7 @@ class _RedisCluster:
         readonly_mode: bool = False,
         hosts: list[dict[Any, Any]] | dict[Any, Any] | None = None,
         client_args: dict[str, Any] | None = None,
-        **config,
+        **config: Any,
     ) -> SimpleLazyObject:
         # StrictRedisCluster expects a list of { host, port } dicts. Coerce the
         # configuration into the correct format if necessary.