# Override decorator

While working with pyglet one day, I made the mistake of subclassing the window class and overriding the __init__ method, which prevented the window from showing. To fix this, it’s easy enough to add a call to super(Window, self).__init__(*args, **kwargs), but I went a different route. Here’s a decorator called override that puts it in for you:

def override(function):
    def wrapper(instance, *args, **kwargs):
        super(instance.__class__, instance).__init__(*args, **kwargs)
        return function(instance, *args, **kwargs)
    return wrapper

To use it, simply use the decorator notation in a subclassed method:

class MyWindow(pyglet.window.Window):
    @override
    def __init__(self, *args, **kwargs):
        # code goes here, no need to call super!