dunder-docs (was Python is DOOMED! Again!)

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Feb 2 09:20:39 EST 2015


Devin Jeanpierre wrote:

> Oops, I just realized why such a claim might be made: the
> documentation probably wants to be able to say that any method can use
> super(). So that's why it claims that it isn't a method unless it's
> defined inside a class body.


You can use super anywhere, including outside of classes. The only thing you
can't do is use the Python 3 "super hack" which automatically fills in the
arguments to super if you don't supply them. That is compiler magic which
truly does require the function to be defined inside a class body. But you
can use super outside of classes:


py> class A(list):
...     pass
...
py> x = super(A)  # Unbound super object!
py> x.__get__(A).append
<method 'append' of 'list' objects>
py> a = A()
py> x.__get__(a).append
<built-in method append of A object at 0xb7b8beb4>



-- 
Steven




More information about the Python-list mailing list