在 Python CAPI 中,如果“__new__”不返回类或其实例,则不会调用“__init__”,它在哪里说?

Where does it says in the Python CAPI that if `__new__` does not return the class or an instance of it, `__init__` will not be called?

提问人:Jim 提问时间:8/12/2023 更新时间:8/12/2023 访问量:27

问:

在 Python 的文档中,据说如果类的方法既不返回类本身也不返回类的实例,则不会调用相应的方法。__new____init__

这在 Python C-API 中在哪里实现?

我已经搜索了 https://github.com/python/cpython/blob/main/Objects/typeobject.c#L3682 但找不到相关的实现。

Python 构造函数 cpython 分配器

评论

1赞 Mechanic Pig 8/12/2023
这里
0赞 Jim 8/12/2023
@MechanicPig 美丽!感谢您的帮助!

答: 暂无答案