Skip to content

Commit

Permalink
Refactor and add new method for configuration handling
Browse files Browse the repository at this point in the history
Remove redundant attribute check in __init__ method and simplify its initialization. Add a new `get` method to access configuration values more explicitly and efficiently.
  • Loading branch information
SalvatoreZagaria committed Sep 28, 2024
1 parent 622bea5 commit 25efec0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tenacity/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def __new__(cls):
return cls._instance

def __init__(self):
if not hasattr(self, '_config'):
self._config = {}
self._config = {}

def set_config(self, **kwargs: t.Any) -> None:
"""Sets multiple configuration parameters."""
Expand Down Expand Up @@ -81,6 +80,9 @@ def get_config(self, override: t.Optional[t.Dict[str, t.Any]] = None) -> t.Dict[
def reset_config(self):
self._config = {}

def get(self, name: str) -> t.Any:
return self._config.get(name)

def __getattr__(self, name: str) -> t.Any:
return self._config.get(name)

Expand Down

0 comments on commit 25efec0

Please sign in to comment.