What does this mean that the returned super object is being returned in python?

According to http://docs.python.org/2/library/functions.html#super ,

If the second argument is omitted, the super object is unbound.

What is super (type).

I wonder what is unlimited and when it is limited.

+7
python super class
source share
2 answers

Edit: in the super context, most of the below is incorrect. See Commentary by John W.

super(Foo, a).bar returns a method called bar from the next object in method resolution order (MRO), in this case bound to object a , an instance of Foo . If a was omitted, then the return method would be unbound. Methods are just objects, but they can be related or not related.

An unbound method is a method that is not bound to an instance of the class. It does not receive an instance of the class as an implicit first argument.

You can still call unrelated methods, but you need to pass an instance of the class explicitly as the first argument.

The following is an example of a related and unrelated method and how to use them.

 In [1]: class Foo(object): ...: def bar(self): ...: print self ...: In [2]: Foo.bar Out[2]: <unbound method Foo.bar> In [3]: a = Foo() In [4]: a.bar Out[4]: <bound method Foo.bar of <__main__.Foo object at 0x4433110>> In [5]: a.bar() <__main__.Foo object at 0x4433110> In [6]: Foo.bar() --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-6-bb3335dac614> in <module>() ----> 1 Foo.bar() TypeError: unbound method bar() must be called with Foo instance as first argument (got nothing instead) In [7]: Foo.bar(a) <__main__.Foo object at 0x4433110> 
+2
source share

"Unbound" means that it will return a class, not an instance of the class.

0
source share

All Articles