gpt4 book ai didi

python - 具有空 __bases__ 属性的自定义类

转载 作者:太空狗 更新时间:2023-10-30 01:12:43 24 4
gpt4 key购买 nike

在关于 Custom Classes 的部分的 The Python Language Reference据称:

Special attributes: __name__ is the class name; __module__ is the module name in which the class was defined; __dict__ is the dictionary containing the class’s namespace; __bases__ is a tuple (possibly empty or a singleton) containing the base classes, in the order of their occurrence in the base class list; __doc__ is the class’s documentation string, or None if undefined.

那么,自定义类的 __bases__ 可以“可能为空”吗?如果在 Python 3 中所有内容都隐式继承自 object,那如何实现?

唯一具有空 __bases__ 的类是 object 本身:

>>> object.__bases__
()

我错过了什么吗?

最佳答案

这条线在 Python 3 发布之前就已经存在了。这是 2007 commit .当对象模型被修改以摆脱旧式类时,看起来文档中的信息没有通过审查,现在可能只是错误信息。

我可以建议你提出一个 documentation issue清除它是否不正确/过时。

关于python - 具有空 __bases__ 属性的自定义类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40697047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com