code quality fixes
This commit is contained in:
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user