Skip to content

Commit

Permalink
Don't return bool on strategy eval
Browse files Browse the repository at this point in the history
  • Loading branch information
benmezger committed May 3, 2024
1 parent cec9648 commit a1a4482
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions pyretries/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def should_stop(self) -> bool:
raise NotImplementedError

@abc.abstractmethod
def eval(self, value: StrategyValueT | Exception | None) -> bool:
def eval(self, value: StrategyValueT | Exception | None):
"""
Evaluates strategy.
Expand Down Expand Up @@ -81,7 +81,7 @@ def should_stop(self) -> bool:
return True
return False

def eval(self, value: StrategyValueT | Exception | None) -> bool:
def eval(self, value: StrategyValueT | Exception | None):
"""
Evaluates strategy.
Expand All @@ -103,7 +103,6 @@ def eval(self, value: StrategyValueT | Exception | None) -> bool:
_logger.info(f"{self.__class__.__name__} is at {self.current_attempt=}")

self.current_attempt += 1
return True


class SleepStrategy(Strategy, t.Generic[StrategyValueT]):
Expand Down Expand Up @@ -132,7 +131,7 @@ def should_stop(self) -> bool:
return True
return False

def eval(self, value: StrategyValueT | Exception | None) -> bool:
def eval(self, value: StrategyValueT | Exception | None):
"""
Evaluates strategy.
Expand All @@ -159,8 +158,6 @@ def eval(self, value: StrategyValueT | Exception | None) -> bool:
)
time.sleep(self.seconds)

return True


class NoopStrategy(Strategy, t.Generic[StrategyValueT]):
"Do nothing strategy"
Expand All @@ -186,7 +183,7 @@ def should_stop(self) -> bool:
return True
return False

def eval(self, value: StrategyValueT | Exception | None) -> bool:
def eval(self, value: StrategyValueT | Exception | None):
"""
Evaluates strategy.
Expand All @@ -205,7 +202,6 @@ def eval(self, value: StrategyValueT | Exception | None) -> bool:
)

self.current_attempt += 1
return True


class StopWhenReturnValueStrategy(Strategy, t.Generic[StrategyValueT]):
Expand Down Expand Up @@ -237,7 +233,7 @@ def should_stop(self) -> bool:
return True
return False

def eval(self, value: StrategyValueT | Exception | None) -> bool:
def eval(self, value: StrategyValueT | Exception | None):
"""
Evaluates strategy.
Expand All @@ -262,8 +258,6 @@ def eval(self, value: StrategyValueT | Exception | None) -> bool:
)
self.current_attempt += 1

return not value == self.expected


class ExponentialBackoffStrategy(Strategy, t.Generic[StrategyValueT]):
"""Exponential backoff strategy"""
Expand Down Expand Up @@ -292,7 +286,7 @@ def should_stop(self) -> bool:
return True
return False

def eval(self, value: StrategyValueT | Exception | None) -> bool:
def eval(self, value: StrategyValueT | Exception | None):
"""
Evaluates strategy.
Expand Down Expand Up @@ -320,4 +314,4 @@ def eval(self, value: StrategyValueT | Exception | None) -> bool:
)

time.sleep(self.delay)
return True

2 changes: 1 addition & 1 deletion tests/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_return_value(self, attempts: int):
s = strategy.StopWhenReturnValueStrategy(expected=attempts, max_attempts=2)
assert s.current_attempt == 0

assert s.eval(attempts) is False
s.eval(attempts)
assert s.current_attempt == 1

def test_raises_when_max_attempts(self):
Expand Down

0 comments on commit a1a4482

Please sign in to comment.