Skip to content

Commit ae849ba

Browse files
authored
Merge pull request optuna#5840 from boringbyte/fix/_redis.py
Simplify type annotations for `optuna/storages/journal/_redis.py`
2 parents a92b168 + 0a5d2a1 commit ae849ba

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

optuna/storages/journal/_redis.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
from __future__ import annotations
2+
13
import json
24
import time
35
from typing import Any
4-
from typing import Dict
5-
from typing import List
6-
from typing import Optional
76

87
from optuna._deprecated import deprecated_class
98
from optuna._experimental import experimental_class
@@ -44,16 +43,16 @@ def __init__(self, url: str, use_cluster: bool = False, prefix: str = "") -> Non
4443
self._use_cluster = use_cluster
4544
self._prefix = prefix
4645

47-
def __getstate__(self) -> Dict[Any, Any]:
46+
def __getstate__(self) -> dict[Any, Any]:
4847
state = self.__dict__.copy()
4948
del state["_redis"]
5049
return state
5150

52-
def __setstate__(self, state: Dict[Any, Any]) -> None:
51+
def __setstate__(self, state: dict[Any, Any]) -> None:
5352
self.__dict__.update(state)
5453
self._redis = redis.Redis.from_url(self._url)
5554

56-
def read_logs(self, log_number_from: int) -> List[Dict[str, Any]]:
55+
def read_logs(self, log_number_from: int) -> list[dict[str, Any]]:
5756
max_log_number_bytes = self._redis.get(f"{self._prefix}:log_number")
5857
if max_log_number_bytes is None:
5958
return []
@@ -75,7 +74,7 @@ def read_logs(self, log_number_from: int) -> List[Dict[str, Any]]:
7574
raise err
7675
return logs
7776

78-
def append_logs(self, logs: List[Dict[str, Any]]) -> None:
77+
def append_logs(self, logs: list[dict[str, Any]]) -> None:
7978
self._redis.setnx(f"{self._prefix}:log_number", -1)
8079
for log in logs:
8180
if not self._use_cluster:
@@ -93,7 +92,7 @@ def append_logs(self, logs: List[Dict[str, Any]]) -> None:
9392
def save_snapshot(self, snapshot: bytes) -> None:
9493
self._redis.set(f"{self._prefix}:snapshot", snapshot)
9594

96-
def load_snapshot(self) -> Optional[bytes]:
95+
def load_snapshot(self) -> bytes | None:
9796
snapshot_bytes = self._redis.get(f"{self._prefix}:snapshot")
9897
return snapshot_bytes
9998

0 commit comments

Comments
 (0)