File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77Enables selecting an algorithm at runtime.
88"""
99
10+
1011from __future__ import annotations
1112
1213from typing import Callable , Type
1314
1415
1516class 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 ):
You can’t perform that action at this time.
0 commit comments