Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save vanlummelhuizen/50852af25b4bb7af08f3e5c09a72f32d to your computer and use it in GitHub Desktop.

Select an option

Save vanlummelhuizen/50852af25b4bb7af08f3e5c09a72f32d to your computer and use it in GitHub Desktop.
Class decorator with method overriding
def my_class_decorator(cls):
class NewClass(cls):
def my_method(self, *args, **kwargs):
print("I am the extended my_method.")
super(NewClass, self).my_method(*args, **kwargs)
print("I am the extended my_method, again.")
return NewClass
@my_class_decorator
class MyClass:
def my_method(*args, **kwargs):
print("I am the original my_method.")
if __name__ == '__main__':
obj = MyClass()
obj.my_method()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment