code quality fixes
Code Quality Pipeline / code-quality (pull_request) Successful in 30s
Test Python Package / test (pull_request) Successful in 1m12s

This commit is contained in:
Brian Bjarke Jensen
2025-09-17 12:14:37 +02:00
parent 538b26b62f
commit 396cf83a05
2 changed files with 19 additions and 23 deletions
+9 -10
View File
@@ -1,7 +1,8 @@
"""Definition of RedisAdapter class."""
from __future__ import annotations
from typing import cast, TYPE_CHECKING
from typing import cast
from importlib.util import find_spec
import os
import structlog
@@ -12,10 +13,13 @@ from python_repositories.interfaces import (
ConnectionAwareInterface,
)
# Import for mypy type checking only
if TYPE_CHECKING:
# Handle optional dependencies
if find_spec("redis") is not None:
import redis
from redis.commands.json.path import Path as RedisPath
else:
redis = None # type: ignore
RedisPath = None # type: ignore
class RedisAdapter(
@@ -25,16 +29,10 @@ class RedisAdapter(
"""Redis adapter exposing basic CRUD functionality."""
uri_env_var_name: str = "REDIS_URI"
path: str = RedisPath.root_path()
path: str = "." # JSON root path, updated in __init__
encoding: str = "UTF-8"
def __init__(self) -> None:
# Import here to avoid hard dependency to optional package
try:
import redis
from redis.commands.json.path import Path as RedisPath
except ImportError as e:
raise RuntimeError("RedisAdapter dependencies missing") from e
# Setup logger
self.logger = structlog.get_logger(
self.__class__.__name__,
@@ -43,6 +41,7 @@ class RedisAdapter(
check_env(self.uri_env_var_name)
# Prepare internal variables
self._client: redis.Redis | None = None
self.path: str = RedisPath.root_path()
def __enter__(self) -> RedisAdapter:
"""Enter the context."""