1def logic_mixin_factory(duck_mass: int,
2 mass_attr_name: str,
3 material: str,
4 material_attr_name: str,
5 float_method_name: str):
6 class LogicMixin:
7
8 def __has_mass_of_a_duck(self):
9 try:
10 return getattr(self, mass_attr_name) == duck_mass
11 except AttributeError:
12 return False
13
14 def __can_float(self):
15 try:
16 float_method = getattr(self, float_method_name)
17 return '__call__' in dir(float_method)
18 except AttributeError:
19 return False
20
21 def __is_made_of_wood(self):
22 try:
23 return getattr(self, material_attr_name) == material
24 except AttributeError:
25 return False
26
27 def is_a_witch(self):
28 if self.__has_mass_of_a_duck() or self.__can_float() or self.__is_made_of_wood():
29 return "Burn her!"
30 return "No, but it's a pity, cuz she looks like a witch!"
31
32 return LogicMixin
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
f | 1 | def logic_mixin_factory(duck_mass: int, | f | 1 | def logic_mixin_factory(duck_mass: int, |
2 | mass_attr_name: str, | 2 | mass_attr_name: str, | ||
3 | material: str, | 3 | material: str, | ||
4 | material_attr_name: str, | 4 | material_attr_name: str, | ||
5 | float_method_name: str): | 5 | float_method_name: str): | ||
6 | class LogicMixin: | 6 | class LogicMixin: | ||
7 | 7 | ||||
8 | def __has_mass_of_a_duck(self): | 8 | def __has_mass_of_a_duck(self): | ||
9 | try: | 9 | try: | ||
10 | return getattr(self, mass_attr_name) == duck_mass | 10 | return getattr(self, mass_attr_name) == duck_mass | ||
11 | except AttributeError: | 11 | except AttributeError: | ||
12 | return False | 12 | return False | ||
13 | 13 | ||||
14 | def __can_float(self): | 14 | def __can_float(self): | ||
15 | try: | 15 | try: | ||
16 | float_method = getattr(self, float_method_name) | 16 | float_method = getattr(self, float_method_name) | ||
17 | return '__call__' in dir(float_method) | 17 | return '__call__' in dir(float_method) | ||
18 | except AttributeError: | 18 | except AttributeError: | ||
19 | return False | 19 | return False | ||
20 | 20 | ||||
21 | def __is_made_of_wood(self): | 21 | def __is_made_of_wood(self): | ||
22 | try: | 22 | try: | ||
23 | return getattr(self, material_attr_name) == material | 23 | return getattr(self, material_attr_name) == material | ||
24 | except AttributeError: | 24 | except AttributeError: | ||
25 | return False | 25 | return False | ||
26 | 26 | ||||
27 | def is_a_witch(self): | 27 | def is_a_witch(self): | ||
28 | if self.__has_mass_of_a_duck() or self.__can_float() or self.__is_made_of_wood(): | 28 | if self.__has_mass_of_a_duck() or self.__can_float() or self.__is_made_of_wood(): | ||
29 | return "Burn her!" | 29 | return "Burn her!" | ||
t | 30 | return "No, but it's a pitty, cuz she looks like a witch!" | t | 30 | return "No, but it's a pity, cuz she looks like a witch!" |
31 | 31 | ||||
32 | return LogicMixin | 32 | return LogicMixin |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|