Which class was written first in Python: type or object?

Viewed 47

All classes are subclasses of the object and at the same time they all are instances of the type. Therefore, the object is an instance of the type, and the type is an subclass of the object. But, obviously, one of these connections is fictitious. Which class in the implementation of python is written first?

1 Answers

Both were written at the same time, when the "new style classes" were created, during the development cycle that ended up in Python 2.2. The development of that version made explicit and formalized the metaclass mechanism, and object and type are bound from their inception.

While it is impossible for one, in plain (or even arcane) Python code to create a class that is both a supertype of your class and an instance of it, as object is to type, when coding the classes in lower level, in the case of cPython, in the C source code of the language, that is perfectly possible: both are statically declared, and the plain forward reference used by the C pre-processor is enough to be able to refer to object in type's slots before object's code is declared and vice versa.

You may want to read some posts from the time the new style classes where created, and this is a good starting point: https://www.python.org/download/releases/2.2.3/descrintro/

Related