Skip to content

Instantly share code, notes, and snippets.

@bplaxco
Created October 2, 2016 14:20
Show Gist options
  • Save bplaxco/3c2791bc4af633e5c8961b251bf924b5 to your computer and use it in GitHub Desktop.
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)
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