Chapter 3. Wrap Up

The Python Objects Map

We really ended up with a map of different kinds of Python objects in the last chapter.

Figure 3.1. The Python Objects Map

The Python Objects Map

Here we also unravel the mystery of the vertical grey lines. They just segregate objects into three spaces based on what the common man calls them - metaclasses, classes, or instances.

Some interesting points to note:

  1. Dashed lines cross spacial boundaries (i.e. go from object to meta-object). Only exception is <type 'type'> (which is good, otherwise we would need another space to the left of it, and another, and another...).

  2. Solid lines do not cross space boundaries. Again, <type 'type'> -> <type 'object'> is an exception.

  3. Solid lines are not allowed in the rightmost space. These objects are too concrete to be subtyped.

  4. Dashed line arrow heads are not allowed rightmost space. These objects are too concrete to be instantiated.

  5. Left two spaces contain type objects. Rightmost space contains non-type objects.

  6. If we created a new object by subtyping <type 'type'> it would be in the leftmost space, and would also be both a subtype and instance of <type 'type'>.

Also note that <type 'type'> is indeed a type of all types, and <type 'object'> a supertype of all types (except itself).