Skip to content

Commit b8849c1

Browse files
resolve review
1 parent 7f71d37 commit b8849c1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

patterns/behavioral/strategy.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,26 @@
77
Enables selecting an algorithm at runtime.
88
"""
99

10+
1011
from __future__ import annotations
1112

1213
from typing import Callable, Type
1314

1415

1516
class DiscountStrategyValidator: # Descriptor class for check perform
16-
def validate(self, obj: Order, value: Callable) -> bool:
17+
@staticmethod
18+
def validate(obj: Order, value: Callable) -> bool:
1719
try:
1820
if obj.price - value(obj) < 0:
1921
raise ValueError(f"Discount cannot be applied due to negative price resulting. {value.__name__}")
20-
return True
2122
except ValueError as ex:
2223
print(str(ex))
2324
return False
25+
else:
26+
return True
2427

2528
def __set_name__(self, owner, name: str) -> None:
26-
self.private_name = '_' + name
29+
self.private_name = f"_{name}"
2730

2831
def __set__(self, obj: Order, value: Callable = None) -> None:
2932
if value and self.validate(obj, value):

0 commit comments

Comments
 (0)