Skip to content

Instantly share code, notes, and snippets.

@juanarrivillaga
Last active January 23, 2023 01:23
Show Gist options
  • Save juanarrivillaga/0d4d2d489347777bc21f9e150149b093 to your computer and use it in GitHub Desktop.
Save juanarrivillaga/0d4d2d489347777bc21f9e150149b093 to your computer and use it in GitHub Desktop.
An example of how we could implement a basic `super` in pure Python
class SimpleSuper:
def __init__(self, cls, instance):
self.cls = cls
self.instance = instance
def __getattr__(self, name):
mro = type(self.instance).mro()
next_cls = mro[mro.index(self.cls) + 1]
attribute = getattr(next_cls, name)
if hasattr(attribute, "__get__"):
return attribute.__get__(self.instance, self.cls)
return attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment