Created
October 2, 2016 14:20
-
-
Save bplaxco/3c2791bc4af633e5c8961b251bf924b5 to your computer and use it in GitHub Desktop.
An implementation of Java's Override annotation as a python decorator. (Only lightly tested)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Annotation(object): | |
def __init__(self, method): | |
self.method = method | |
# end __init__ | |
def __get__(self, obj, objtype): | |
return lambda *args, **kwargs: self.__call__(obj, *args, **kwargs) | |
# end __get__ | |
# end Annotation | |
class Override(Annotation): | |
def __call__(self, obj, *args, **kwargs): | |
# Check that parrent has the method | |
getattr(super(obj.__class__, obj), self.method.__name__) | |
return self.method(obj, *args, **kwargs) | |
# end __call__ | |
# end Override |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment