Primary
__new__() ⚬|Documentation|1st|20260110180314-00-⌔
3. Data model — Python 3 documentation#object.new
object.__new__(cls[,...])Called to create a new instance of class cls.
__new__()is a static method (special-cased so you need not declare it as such) that takes the class of which an instance was requested as its first argument. The remaining arguments are those passed to the object constructor expression (the call to the class). The return value of__new__()should be the new object instance (usually an instance of cls).Typical implementations create a new instance of the class by invoking the superclass’s
__new__()method usingsuper().__new__(cls[,...])with appropriate arguments and then modifying the newly created instance as necessary before returning it.If
__new__()is invoked during object construction and it returns an instance of cls, then the new instance’s__init__()method will be invoked like__init__(self[,...]), where self is the new instance and the remaining arguments are the same as were passed to the object constructor.If
__new__()does not return an instance of cls, then the new instance’s__init__()method will not be invoked.
__new__()is intended mainly to allow subclasses of immutable types (like int, str, or tuple) to customize instance creation. It is also commonly overridden in custom metaclasses in order to customize class creation.Printed 2026-06-28.
(echo:: @ ᯤ)
Link to original
Secondary
• • •