f | def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name): | f | def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name): |
| | | |
| | | |
| class LogicMixin: | | class LogicMixin: |
| def __init__(self, mass, mass_attr_name, material, material_attr_name, float_method_name): | | def __init__(self, mass, mass_attr_name, material, material_attr_name, float_method_name): |
n | self.float_method_name = float_method_name | n | |
| setattr(self, mass_attr_name, mass) | | setattr(self, mass_attr_name, mass) |
| setattr(self, material_attr_name, material) | | setattr(self, material_attr_name, material) |
n | | n | setattr(self, float_method_name, lambda: None) |
| | | |
| def is_a_witch(self): | | def is_a_witch(self): |
| if hasattr(self, mass_attr_name) and getattr(self, mass_attr_name) == mass: | | if hasattr(self, mass_attr_name) and getattr(self, mass_attr_name) == mass: |
| return "Burn her!" | | return "Burn her!" |
| elif hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material: | | elif hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material: |
| return "Burn her!" | | return "Burn her!" |
| elif hasattr(self, float_method_name) and callable(getattr(self, float_method_name)): | | elif hasattr(self, float_method_name) and callable(getattr(self, float_method_name)): |
| return "Burn her!" | | return "Burn her!" |
| else: | | else: |
| return "No, but it's a pity, cuz she looks like a witch!" | | return "No, but it's a pity, cuz she looks like a witch!" |
| | | |
| | | |
| return LogicMixin | | return LogicMixin |
t | | t | |