object.rst 16.3 KB

Object Protocol

Subclass determination is done in a fairly straightforward way, but includes a wrinkle that implementors of extensions to the class system may want to be aware of. If :class:`A` and :class:`B` are class objects, :class:`B` is a subclass of :class:`A` if it inherits from :class:`A` either directly or indirectly. If either is not a class object, a more general mechanism is used to determine the class relationship of the two objects. When testing if B is a subclass of A, if A is B, :cfunc:`PyObject_IsSubclass` returns true. If A and B are different objects, B's :attr:`__bases__` attribute is searched in a depth-first fashion for A --- the presence of the :attr:`__bases__` attribute is considered sufficient for this determination.