Skip to content

Commit

Permalink
Refactor tenacity/config.py to add type annotations
Browse files Browse the repository at this point in the history
Updated the singleton implementation and added type annotations to various methods and attributes in the DictConfig class. This improves code readability and helps with static type checking.
  • Loading branch information
SalvatoreZagaria committed Sep 28, 2024
1 parent 93e5427 commit cbd7d3f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tenacity/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ class DictConfig:
- __repr__: Returns a string representation of the configuration object.
"""

_instance = None
_instance: t.Optional["DictConfig"] = None
_lock = Lock() # For thread safety

def __new__(cls):
def __new__(cls) -> "DictConfig":
if cls._instance is None:
with cls._lock:
if cls._instance is None:
cls._instance = super().__new__(cls)
return cls._instance

def __init__(self):
self._config = {}
def __init__(self) -> None:
self._config: t.Dict[str, t.Any] = {}

def set_config(self, **kwargs: t.Any) -> None:
"""Sets multiple configuration parameters."""
Expand Down Expand Up @@ -80,7 +80,7 @@ def get_config(
config.update(override)
return config

def reset_config(self):
def reset_config(self) -> None:
self._config = {}

def get(self, name: str) -> t.Any:
Expand Down

0 comments on commit cbd7d3f

Please sign in to comment.