Skip to content

Instantly share code, notes, and snippets.

@jiaaro
Last active December 10, 2015 18:49
Show Gist options
  • Save jiaaro/4477229 to your computer and use it in GitHub Desktop.
Save jiaaro/4477229 to your computer and use it in GitHub Desktop.
Magical, automatic super class caller in python (a terrible idea)
import inspect
def magicsuper(*args, **kwargs):
frame = inspect.currentframe().f_back
first_arg_name = frame.f_code.co_varnames[0]
self = frame.f_locals[first_arg_name]
super_klass = super(self.__class__, self)
return getattr(super_klass, frame.f_code.co_name)(*args, **kwargs)
# Example Use:
class X(object):
def y(self, z):
print z
class Y(X):
def y(self, z):
return magicsuper(z)
y = Y()
y.y('hi mom') # output: "hi mom"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment