Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean by the 'super object returned is unbound' in python?

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

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

Which is super(type).

I am wondering what is unbounded and when is it bounded.

like image 241
dspjm Avatar asked Mar 14 '14 11:03

dspjm


1 Answers

To explain terms bound / unbound I will use functions, and — to be brief — I give up details and caveats.

There are 2 views:


  1. From the user point of view there are 3 sorts of functions:
    1. Free function (unbound), for example the built-in function sum():

      sum([1, 2, 3])          # 6
      
    2. A function bound to an object (other name: object method) means that a user have to bind it to a particular object with the dot (.) notation.

      For example the use of built-in .upper() method:

      "Alice".upper()     # ALICE
      "Jacob".upper()     # JACOB (the same method; different object, different result)
      
    3. A function bound to a class (other name: class method) means that a user have to bind it to a particular class — again with the same dot (.) notation.

      Examples:

      A.some_class_method()               # A is a class
      B.some_class_method(parameters)     # B is a class
      

  1. From the designer point of view there are the same 3 sorts of functions, so I use the same numbers for them:

    1. A free (unbound) function is defined out of a class:

      def free_function(parameters):
          ...
      
    2. A function bound to an object is defined inside a class, with the first parameter reserved for an object and named self (this name is only a convention, but a very strong one):

      class A:
          def bound_to_object(self, other_parameters):
              ...
      
    3. A function bound to a class is defined inside a class, with the first parameter reserved for a class and named cls (this name is only a convention, too, but a very strong one) and with the @classmethod decorator just before it:

      class A:
          @classmethod
          def bound_to_class(cls, other_parameters):
              ...
      
like image 143
MarianD Avatar answered Sep 28 '22 08:09

MarianD