Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8683879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:09:27+00:00 2026-06-12T22:09:27+00:00

I understand what __new__ does (and how it’s different from __init__ ) so I’m

  • 0

I understand what __new__ does (and how it’s different from __init__) so I’m not interested in definitions, I’m interested in when and how to use __new__.

The documentation says:

In general, you shouldn’t need to override __new__ unless you’re subclassing an immutable type like str, int, unicode or tuple

But I can’t think of other cases to use __new__ or how to use it correctly (for example when subclassing an immutable type or why it’s needed in this case).

So, when, why and how do you need to use __new__?

I’m interested in the use cases, not what it does (I know what it does).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:09:28+00:00Added an answer on June 12, 2026 at 10:09 pm

    Answering for myself, I’ve used it to

    • create a singleton pattern (though there are ways to do that without using __new__)
    • dynamically extend classes from external modules without actually editing the source
    • customize classes in a metaclass (though __call__ may also be used I think)
    • extend a the datetime.datetime class (which is immutable) to return the current time if instanciated without arguments and the result of calling strptime on the argument if called with a single string argument

    You need __new__ when subclassing an immutable type if you want to alter the arguments used to construct the immutable, as I wanted in the datetime example, or if you don’t want to call the parent __new__ at all but return an instance created another way or even of an entirely different type. By the time you’re in __init__ it’s too late to alter the object in any way, so you need to do it in __new__.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not quite understand why does Object.GetHashCode() return different values for two identical byte
Does anybody try zf2? I can not understand new mechanism of using sessions in
I understand that the TPL does not necessarily create a new thread for every
I am a new developer for android programming. I understand android SDK does not
I don't understand why code first does not add a new item to the
The Android Geocoder does not appear to understand intersections like the web-based Google Maps
I'm new to Python and can't understand why a thing like this does not
New to python and trying to understand multi-threading. Here's an example from python documentation
I don't understand why the following does not work: public void doSomething(int... args){ List<Integer>
I understand dojo's build system, but I'm rather new to Grails. Does anyone know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.