Search code examples
pythoncpythonmethod-resolution-order

Are `.__mro__` and `.mro()` a CPython implementation details?


Pythons type.mro() is documented in section 4.13. Special Attributes which is introduced with:

The implementation adds a few special read-only attributes to several object types, where they are relevant. Some of these are not reported by the dir() built-in function.

Does this mean those are CPython implementation details that may not be present in other Python implementations?


Solution

  • No, these are part of the python object model. You can rely on them being present in other python implementations that conform with the reference implementation. Note that the page specifically says that class.mro can be overridden to customize the class's __mro__.

    Also note that inspect.getmro is available for all python implementations and the __mro__ attribute is also mentioned on the data model page.