Обложка канала

Библиотека Python разработчика

20835 @BookPython

Библиотека Python разработчика. Книги по программированию на Python.

Библиотека Python разработчика

4 года назад
Открыть в
All objects in Python are created via the call to the __new__ method. Even if you provide custom __new__ for your class, you have to call super().__new__(...). You might think that object.__new__ is a root implementation that is responsible for the creation of all objects. That is not entirely true. There are several such implementations, and they are incompatible. For example, dict has its own low-level __new__ and objects of types derived from dict can't be created with object.__new__: In : class D(dict): ...: pass ...: In : class A: ...: pass ...: In : object.__new__(A) Out: <__main__.A at 0x7f200c8902e8> In : object.__new__(D) ... TypeError: object.__new__(D) is not safe, use D.__new__()