Source code for mylinux.libs.decorator

"""
Here are defined all custom decorators.
"""
[docs]def overrides(interface_class): """Decorator to override class method Args: interface_class (cls): Which class is being overrided? Raises: ValueError: If method is not located in interface_class. Return: Method that is overriding interface_class. """ def overrider(method): if not method.__name__ in dir(interface_class): raise ValueError('Method ' + method.__name__ + ' not found in ' + interface_class.__name__) return method return overrider
[docs]def override(function): """To visualy see that you are overriding some class method. Args: function (fun): You can joust do @override and it will pass function in args. Return: Method that is overriding interface_class. """ return function
[docs]class ClassProperty(property): """Make class property (not instance property). Args: property (fun): You can joust do @ClassProperty and fun will be passed in args. Return: Value from property function. """ def __get__(self, cls, owner): return self.fget.__get__(None, owner)()