`.__mro__` 和 `.mro()` 是 CPython 实现细节吗?
Are `.__mro__` and `.mro()` a CPython implementation details?
Pythons type.mro()
is documented in section 4.13. Special Attributes 引入:
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.
这是否意味着那些 CPython 实现细节可能不会出现在其他 Python 实现中?
不,这些是 python 对象模型的一部分。您可以相信它们存在于符合参考实现的其他 python 实现中。请注意,该页面特别指出可以覆盖 class.mro
以自定义 class 的 __mro__
。
另请注意 inspect.getmro
is available for all python implementations and the __mro__
attribute is also mentioned on the data model page.
Pythons type.mro()
is documented in section 4.13. Special Attributes 引入:
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.
这是否意味着那些 CPython 实现细节可能不会出现在其他 Python 实现中?
不,这些是 python 对象模型的一部分。您可以相信它们存在于符合参考实现的其他 python 实现中。请注意,该页面特别指出可以覆盖 class.mro
以自定义 class 的 __mro__
。
另请注意 inspect.getmro
is available for all python implementations and the __mro__
attribute is also mentioned on the data model page.