Circular relationship: object - type

Chris Rebert clp2 at rebertia.com
Sun May 17 06:38:09 EDT 2009


On Thu, May 14, 2009 at 3:34 PM, Mohan Parthasarathy <suruti94 at gmail.com> wrote:
> Hi,
>
> I have read several articles and emails:
>
> http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html#relationships-transitivity-figure
> http://mail.python.org/pipermail/python-list/2007-February/600128.html
>
>  I understand how type serves to be the default metaclass when an object is
> created and it also can be changed. I also read a few examples on why this
> metaclass can be a powerful concept. What I fail to understand is the
> circular relationship between object and type. Why does type have to be
> subclassed from object ? Just to make "Everything is an object and all
> objects are  inherited from object class".

Yes, essentially. It makes the system nice and axiomatic, so one
doesn't have to deal with special-cases when writing introspective
code.

Axiom 1. All classes ultimately subclass the class `object`.
Equivalently, `issubclass(X, object) and X.__mro__[-1] is object` are
true for any class `X`, and `isinstance(Y, object)` is true for all
objects `Y`.

Axiom 2. All (meta)classes are ultimately instances of the (meta)class `type`.
Equivalently, repeated application of type() to any object will
eventually result in `type`.

Any other formulation besides Python's current one would break these
handy axioms. The canonical object-oriented language, Smalltalk, had a
nearly identical setup with regard to its meta-objects.

Cheers,
Chris
-- 
http://blog.rebertia.com



More information about the Python-list mailing list