Python Forum
error occuring in definition a class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error occuring in definition a class
#4
https://docs.python.org/3/reference/data...ct.__new__ Wrote: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 using super().__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.
Reply


Messages In This Thread
error occuring in definition a class - by akbarza - Nov-25-2023, 08:04 AM
RE: error occuring in definition a class - by Yoriz - Nov-25-2023, 02:01 PM
RE: error occuring in definition a class - by Yoriz - Nov-26-2023, 09:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 398 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  mutable argument in function definition akbarza 1 582 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  determine parameter type in definition function akbarza 1 678 Aug-24-2023, 01:46 PM
Last Post: deanhystad
  [split] Explain the python code in this definition Led_Zeppelin 1 808 Jan-13-2023, 10:20 PM
Last Post: deanhystad
  Explain the python code in this definition Led_Zeppelin 1 1,178 Oct-27-2022, 04:04 AM
Last Post: deanhystad
  meaning of -> syntax in function definition DrakeSoft 5 2,134 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Not including a constructor __init__ in the class definition... bytecrunch 3 12,513 Sep-02-2021, 04:40 AM
Last Post: deanhystad
  Something wrong with the quotation mark in dictionary definition Mark17 1 2,086 Jan-29-2021, 03:34 PM
Last Post: buran
  error in class non_name092 1 2,011 Sep-02-2020, 05:42 PM
Last Post: bowlofred
  My class has name error message 357mag 3 2,422 Sep-04-2019, 03:29 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020