Skip to content

Instantly share code, notes, and snippets.

@lig
Last active May 14, 2020 12:13
Show Gist options
  • Save lig/11caec44202e82983ea44edc67fab41e to your computer and use it in GitHub Desktop.
Save lig/11caec44202e82983ea44edc67fab41e to your computer and use it in GitHub Desktop.
super() outside of a class
>>> class A:
... def foo(self):
... return 5
>>> class B(A):
... def foo(self):
... return 3
>>> b = B()
>>> super(B, b).foo()
5
>>> super(A, b).foo()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-6-863be3d3f354> in <module>
----> 1 super(A, b).foo()
AttributeError: 'super' object has no attribute 'foo'
>>> class C(B):
... pass
>>> c = C()
>>> super(B, c).foo()
5
>>> A.foo(c)
5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment