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

  • SEARCH
  • Home
  • 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 7812763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:37:09+00:00 2026-06-02T04:37:09+00:00

The documentation implies that it’s ok for __new__(cls, …) to return an object of

  • 0

The documentation implies that it’s ok for __new__(cls, ...) to return an object of a type different than cls. It says in that case __init__() won’t be called. It’s not stated explicitly, but common sense or a simple test confirms that the resulting the object won’t have type cls.

Why is this seemingly strange behavior allowed? What’s the use case? It’s clearly intentional.

  • 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-02T04:37:12+00:00Added an answer on June 2, 2026 at 4:37 am

    It can be useful when you create mock objects for unit testing.

    You can change the __new__ method to return, in the certain cases, the the other object with the same interface, as original (for example simulating the original class instances’ behaviour), without modifications to the rest of code.

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

Sidebar

Related Questions

The documentation implies that you can either have 3D rendering or framebuffer mode, and
The documentation doesn't say anything about that. When an old object is removed and
The documentation for postMessage implies that cross-domain messaging is possible. However: // When the
The documentation , implies that the connection is always remotely available, but since I
The em-synchrony documentation links to this article which implies that this code with fiber:
The MySQL documentation implies that you can assign one or more of a table's
The documentation for Firebird implies that you can write large (> 60K) strings to
The Beanshell documentation implies that you can run a script using this format on
I am creating a Brightcove plugin. The documentation implies that if you need pass
The Python documentation for unittest implies that the assertRaises() method can be used as

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.