{"id":8080,"date":"2021-01-24T19:24:10","date_gmt":"2021-01-24T13:54:10","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=8080"},"modified":"2026-07-13T12:31:33","modified_gmt":"2026-07-13T07:01:33","slug":"python__new__","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python__new__\/","title":{"rendered":"Python __new__: Control Object Creation Before __init__"},"content":{"rendered":"<p><strong>Quick answer:<\/strong> Python calls __new__ to create or return an instance before __init__ initializes it. Override __new__ mainly for immutable subclasses, controlled instance reuse, or allocation decisions; otherwise ordinary __init__ construction is usually clearer.<\/p>\n<figure class=\"pythonpool-article-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-new-object-creation-b113.png\" alt=\"Python Pool infographic showing __new__ creating an instance before __init__ initializes its attributes in the object construction lifecycle\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Python calls __new__ to create or return an instance before __init__ initializes it; immutable types often need values set in __new__.<\/figcaption><\/figure>\n<p><code>__new__()<\/code> is the Python data model method that creates a new object. It runs before <code>__init__()<\/code>. Most classes do not need to define it, because the inherited implementation from <code>object<\/code> already creates a normal instance.<\/p>\n<p>The difference between <code>__new__()<\/code> and <code>__init__()<\/code> is simple but important. <code>__new__()<\/code> allocates and returns the object. <code>__init__()<\/code> receives that object and fills in starting state. If <code>__new__()<\/code> does not return an instance of the class, Python may skip that class&#8217;s <code>__init__()<\/code>.<\/p>\n<p>The official Python data model documents <a href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__new__\">object.__new__()<\/a> and <a href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__init__\">object.__init__()<\/a>. The Python tutorial on <a href=\"https:\/\/docs.python.org\/3\/tutorial\/classes.html\">classes<\/a> gives broader object-oriented background, and the <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html#super\">super()<\/a> reference explains cooperative parent calls.<\/p>\n<p>Use <code>__new__()<\/code> only when object creation itself needs control. Common examples include immutable type subclasses, controlled caching, singleton-style objects, and advanced frameworks. For ordinary setup, prefer <code>__init__()<\/code> because it is easier to read and less surprising.<\/p>\n<p>A correct <code>__new__()<\/code> method is usually a <code>@staticmethod<\/code>-like class method in practice: it receives <code>cls<\/code>, calls <code>super().__new__(cls)<\/code> or the parent type&#8217;s <code>__new__()<\/code>, and returns the created object. The examples below keep that flow explicit.<\/p>\n<p>When reading code that defines <code>__new__()<\/code>, ask two questions. First, does the method always return the kind of object callers expect? Second, can <code>__init__()<\/code> still run safely after that return? Those questions catch most surprising bugs around caches, immutable values, and alternate object creation paths.<\/p>\n<p>Also remember that <code>__new__()<\/code> is inherited. If a subclass overrides it, parent class behavior may still matter through <code>super()<\/code>. Keep the method small and document the reason it exists, because future maintainers will naturally look for normal setup code in <code>__init__()<\/code>.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#See_The_Creation_Order\" >See The Creation Order<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#Create_An_Immutable_str_Subclass\" >Create An Immutable str Subclass<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#Add_Attributes_After_Creation\" >Add Attributes After Creation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#Reuse_An_Object_From_A_Cache\" >Reuse An Object From A Cache<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#Return_A_Different_Class_Carefully\" >Return A Different Class Carefully<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#Prefer_init_For_Normal_Setup\" >Prefer __init__ For Normal Setup<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#Follow_The_Construction_Order\" >Follow The Construction Order<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#Handle_Immutable_Values_Early\" >Handle Immutable Values Early<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#Keep_Cooperative_Inheritance\" >Keep Cooperative Inheritance<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#Avoid_Accidental_Singleton_State\" >Avoid Accidental Singleton State<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#Separate_Allocation_From_Validation\" >Separate Allocation From Validation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#Test_Identity_And_Initialization\" >Test Identity And Initialization<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/python__new__\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"See_The_Creation_Order\"><\/span>See The Creation Order<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>This example prints from both methods so you can see that <code>__new__()<\/code> runs first.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:105%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class Item:\n    def __new__(cls, name):\n        print(\"__new__ creates the object\")\n        obj = super().__new__(cls)\n        return obj\n\n    def __init__(self, name):\n        print(\"__init__ sets the state\")\n        self.name = name\n\nitem = Item(\"book\")\nprint(item.name)\n<\/code><\/pre>\n<\/div>\n<p>The object returned by <code>__new__()<\/code> becomes <code>self<\/code> inside <code>__init__()<\/code>. That is why <code>__init__()<\/code> can set attributes on the object but does not create it from scratch.<\/p>\n<p>For normal classes, this custom <code>__new__()<\/code> method is unnecessary. It is shown here only to make the call order visible.<\/p>\n<p>If this example looks too verbose for ordinary class setup, that is the point. Most application classes should not spell out object allocation.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Create_An_Immutable_str_Subclass\"><\/span>Create An Immutable str Subclass<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Immutable built-in types such as <code>str<\/code>, <code>tuple<\/code>, and <code>int<\/code> need their value during creation. That makes <code>__new__()<\/code> the right place to normalize the stored value.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:105%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class Slug(str):\n    def __new__(cls, text):\n        cleaned = text.strip().lower().replace(\" \", \"-\")\n        return super().__new__(cls, cleaned)\n\nslug = Slug(\" Python New Method \")\n\nprint(slug)\nprint(isinstance(slug, str))\n<\/code><\/pre>\n<\/div>\n<p>The string value is already fixed by the time <code>__init__()<\/code> would run. Using <code>__new__()<\/code> lets the subclass choose the final text before the immutable string object exists.<\/p>\n<p>This pattern is useful for small value types, but it should stay simple. Heavy parsing or I\/O inside <code>__new__()<\/code> makes object creation harder to reason about.<\/p>\n<p>If normalization might fail with a detailed validation message, a separate factory function can be clearer than putting every rule inside the allocation step.<\/p>\n<p><!-- Python Pool visual layout repair 2026-07-13 --><\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/new-call-b179.png\" alt=\"Python Pool infographic showing class call, __new__, object allocation, and instance creation\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Object call: Class call, __new__, object allocation, and instance creation.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Add_Attributes_After_Creation\"><\/span>Add Attributes After Creation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>__new__()<\/code> creates the object, while <code>__init__()<\/code> can still add ordinary attributes when the type allows them.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:105%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class Product:\n    def __new__(cls, name, price):\n        obj = super().__new__(cls)\n        return obj\n\n    def __init__(self, name, price):\n        self.name = name\n        self.price = price\n\nproduct = Product(\"keyboard\", 50)\n\nprint(product.name)\nprint(product.price)\n<\/code><\/pre>\n<\/div>\n<p>This split is rarely needed for normal mutable classes, but it shows the division of responsibility. Creation happens first, setup follows second.<\/p>\n<p>If all you need is attributes such as <code>name<\/code> and <code>price<\/code>, write only <code>__init__()<\/code> and let Python inherit the standard creation behavior.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Reuse_An_Object_From_A_Cache\"><\/span>Reuse An Object From A Cache<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>__new__()<\/code> can return an existing object. This is one reason caching and singleton patterns are usually implemented there instead of in <code>__init__()<\/code>.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:105%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class SmallCode:\n    _cache = {}\n\n    def __new__(cls, code):\n        if code not in cls._cache:\n            obj = super().__new__(cls)\n            obj.code = code\n            cls._cache = obj\n        return cls._cache\n\nfirst = SmallCode(\"A1\")\nsecond = SmallCode(\"A1\")\n\nprint(first is second)\nprint(first.code)\n<\/code><\/pre>\n<\/div>\n<p>The two calls return the same object because the code already exists in the cache. This can be useful for tiny immutable-like value objects.<\/p>\n<p>Be careful with cached mutable objects. If one part of the program changes a shared object, every caller that receives the same cached object sees that change.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Return_A_Different_Class_Carefully\"><\/span>Return A Different Class Carefully<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If <code>__new__()<\/code> returns an object that is not an instance of the class being called, Python does not run that class's <code>__init__()<\/code>.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:105%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class TextOrNumber:\n    def __new__(cls, value):\n        if isinstance(value, int):\n            return value\n        return str(value)\n\nresult_one = TextOrNumber(7)\nresult_two = TextOrNumber(\"seven\")\n\nprint(result_one, type(result_one).__name__)\nprint(result_two, type(result_two).__name__)\n<\/code><\/pre>\n<\/div>\n<p>This behavior is powerful but easy to overuse. In most application code, a named factory function or <code>@classmethod<\/code> constructor is clearer than a class call that returns an unexpected type.<\/p>\n<p>Use this style only when the class's public contract clearly says object creation may return an existing or different object.<\/p>\n<p>Unexpected return types can confuse type checkers, tests, and readers. Prefer explicit factory names when the result may not be an instance of the class being called.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/new-new-init-b179.png\" alt=\"Python Pool infographic mapping __new__ to an instance and __init__ to initialization\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>__new__ then __init__: __new__ to an instance and __init__ to initialization.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Prefer_init_For_Normal_Setup\"><\/span>Prefer __init__ For Normal Setup<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The safest rule is to avoid <code>__new__()<\/code> unless creation itself must change. Normal validation and attribute setup belong in <code>__init__()<\/code>.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:105%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class User:\n    def __init__(self, username):\n        if not username:\n            raise ValueError(\"username is required\")\n        self.username = username\n\nuser = User(\"pythonpool\")\n\nprint(user.username)\n<\/code><\/pre>\n<\/div>\n<p>This version is easier to test, inherit, and explain. It uses Python's normal object creation path and puts validation where most readers expect it.<\/p>\n<p>In short, reach for <code>__new__()<\/code> when you need to control the object that gets returned, especially for immutable subclasses or caches. Use <code>__init__()<\/code> for ordinary setup, and prefer named factory methods when alternate construction would be clearer than customizing object allocation.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Follow_The_Construction_Order\"><\/span>Follow The Construction Order<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The class call invokes __new__ first. If it returns an instance of the class, Python then calls __init__ on that instance; if it returns another type, initialization rules change.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/new-subclass-b179.png\" alt=\"Python Pool infographic comparing subclass __new__, immutable types, caching, and returned instances\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Subclass control: Subclass __new__, immutable types, caching, and returned instances.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Handle_Immutable_Values_Early\"><\/span>Handle Immutable Values Early<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Subclasses of int, str, tuple, and similar immutable types must establish their value during __new__. __init__ can configure attributes but cannot replace the already-created immutable value.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Keep_Cooperative_Inheritance\"><\/span>Keep Cooperative Inheritance<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use super().__new__ with the expected arguments when participating in a class hierarchy. Mismatched signatures or skipped base construction can break mixins and multiple inheritance.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Avoid_Accidental_Singleton_State\"><\/span>Avoid Accidental Singleton State<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Returning a cached instance from __new__ changes identity and can make state leak between callers. If reuse is required, document lifecycle, thread safety, and initialization behavior explicitly.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/new-check-b179.png\" alt=\"Python Pool infographic testing signatures, None, singleton patterns, inheritance, and validation\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Construction checks: Signatures, None, singleton patterns, inheritance, and validation.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Separate_Allocation_From_Validation\"><\/span>Separate Allocation From Validation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Validate arguments before expensive work where possible, but keep object creation and initialization responsibilities understandable. A factory function may be clearer than a complex __new__ override.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Test_Identity_And_Initialization\"><\/span>Test Identity And Initialization<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Test subclass construction, immutable values, repeated calls, failed validation, inheritance, pickling when relevant, and whether __init__ runs exactly when expected. Assert identity separately from equality.<\/p>\n<p>Use the <a href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__new__\">official Python data model documentation for __new__<\/a>. Related Python Pool references include <a href=\"https:\/\/www.pythonpool.com\/python-testing-framework\/\">tests<\/a> and <a href=\"2\">object configuration<\/a>.<\/p>\n<p>For related object design, compare <a href=\"https:\/\/www.pythonpool.com\/python-testing-framework\/\">construction tests<\/a>, <a href=\"2\">attribute state<\/a>, and <a href=\"1\">immutable sequence types<\/a> before overriding <code>__new__<\/code>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3>What is the difference between __new__ and __init__?<\/h3>\n<p>__new__ creates or returns the instance, while __init__ initializes an instance that already exists; __new__ runs first.<\/p>\n<h3>When should I override __new__?<\/h3>\n<p>Use it for immutable subclasses, metaclass or allocation concerns, carefully controlled instance reuse, or a construction contract that must choose the instance.<\/p>\n<h3>Why is __new__ useful for immutable types?<\/h3>\n<p>An immutable value must be established during creation, before later initialization can assign attributes, so subclasses such as int or tuple may use __new__.<\/p>\n<h3>Can __new__ return another object?<\/h3>\n<p>Yes, but if it returns an instance of a different type, Python may skip __init__ for the original class; this behavior should be documented and tested.<\/p>\n<p><script type=\"application\/ld+json\">{\"@context\":\"https:\/\/schema.org\",\"@type\":\"FAQPage\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"What is the difference between __new__ and __init__?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"__new__ creates or returns the instance, while __init__ initializes an instance that already exists; __new__ runs first.\"}},{\"@type\":\"Question\",\"name\":\"When should I override __new__?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Use it for immutable subclasses, metaclass or allocation concerns, carefully controlled instance reuse, or a construction contract that must choose the instance.\"}},{\"@type\":\"Question\",\"name\":\"Why is __new__ useful for immutable types?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"An immutable value must be established during creation, before later initialization can assign attributes, so subclasses such as int or tuple may use __new__.\"}},{\"@type\":\"Question\",\"name\":\"Can __new__ return another object?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes, but if it returns an instance of a different type, Python may skip __init__ for the original class; this behavior should be documented and tested.\"}}]}<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understand Python __new__ versus __init__, immutable types, custom allocation, singleton patterns, cooperative inheritance, and safe object construction.<\/p>\n","protected":false},"author":11,"featured_media":34250,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[3411,3409,3408,3413,3412,1055,3407,3410],"class_list":["post-8080","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-__new__-python","tag-__new__-python-3","tag-python-__new__-arguments","tag-python-__new__-constructor","tag-python-__new__-example","tag-python-__new__-vs-__init__","tag-python-class-attributes-__new__","tag-python-find-__new__-examples","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v28.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python __new__: Control Object Creation Before __init__<\/title>\n<meta name=\"description\" content=\"Understand Python __new__ versus __init__, immutable types, custom allocation, singleton patterns, cooperative inheritance, and safe object construction.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python__new__\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python __new__: Control Object Creation Before __init__\" \/>\n<meta property=\"og:description\" content=\"Understand Python __new__ versus __init__, immutable types, custom allocation, singleton patterns, cooperative inheritance, and safe object construction.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python__new__\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-24T13:54:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-13T07:01:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-new-object-creation-b113.png\" \/>\n<meta name=\"author\" content=\"Rohit Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Python Pool\" \/>\n<meta name=\"twitter:description\" content=\"Practical Python tutorials, error fixes, code examples, and project guides.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-new-object-creation-b113.png\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/\"},\"author\":{\"name\":\"Rohit Kumar\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/664ced779ebbb8ddfd3c58a60d6f9d66\"},\"headline\":\"Python __new__: Control Object Creation Before __init__\",\"datePublished\":\"2021-01-24T13:54:10+00:00\",\"dateModified\":\"2026-07-13T07:01:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/\"},\"wordCount\":1183,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/python-new-method-guide-pythonpool.png\",\"keywords\":[\"__new__ python\",\"__new__ python 3\",\"python __new__ arguments\",\"python __new__ constructor\",\"python __new__ example\",\"python __new__ vs __init__\",\"python class attributes __new__\",\"python find __new__ examples\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/\",\"name\":\"Python __new__: Control Object Creation Before __init__\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/python-new-method-guide-pythonpool.png\",\"datePublished\":\"2021-01-24T13:54:10+00:00\",\"dateModified\":\"2026-07-13T07:01:33+00:00\",\"description\":\"Understand Python __new__ versus __init__, immutable types, custom allocation, singleton patterns, cooperative inheritance, and safe object construction.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/python-new-method-guide-pythonpool.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/python-new-method-guide-pythonpool.png\",\"width\":1350,\"height\":650,\"caption\":\"Python __new__ method object creation guide\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python__new__\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pythonpool.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python __new__: Control Object Creation Before __init__\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"name\":\"Python Pool\",\"description\":\"Practical Python tutorials, error fixes, code examples, and project guides.\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pythonpool.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/pythonpool\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/664ced779ebbb8ddfd3c58a60d6f9d66\",\"name\":\"Rohit Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c9a762a12f6bf9093f4c8a7643c0b6a17dd903d9602fae379649d1b050386b1a?s=96&d=wavatar&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c9a762a12f6bf9093f4c8a7643c0b6a17dd903d9602fae379649d1b050386b1a?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c9a762a12f6bf9093f4c8a7643c0b6a17dd903d9602fae379649d1b050386b1a?s=96&d=wavatar&r=g\",\"caption\":\"Rohit Kumar\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python __new__: Control Object Creation Before __init__","description":"Understand Python __new__ versus __init__, immutable types, custom allocation, singleton patterns, cooperative inheritance, and safe object construction.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pythonpool.com\/python__new__\/","og_locale":"en_US","og_type":"article","og_title":"Python __new__: Control Object Creation Before __init__","og_description":"Understand Python __new__ versus __init__, immutable types, custom allocation, singleton patterns, cooperative inheritance, and safe object construction.","og_url":"https:\/\/www.pythonpool.com\/python__new__\/","og_site_name":"Python Pool","article_published_time":"2021-01-24T13:54:10+00:00","article_modified_time":"2026-07-13T07:01:33+00:00","og_image":[{"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-new-object-creation-b113.png","type":"","width":"","height":""}],"author":"Rohit Kumar","twitter_card":"summary_large_image","twitter_title":"Python Pool","twitter_description":"Practical Python tutorials, error fixes, code examples, and project guides.","twitter_image":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-new-object-creation-b113.png","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Rohit Kumar","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python__new__\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python__new__\/"},"author":{"name":"Rohit Kumar","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/664ced779ebbb8ddfd3c58a60d6f9d66"},"headline":"Python __new__: Control Object Creation Before __init__","datePublished":"2021-01-24T13:54:10+00:00","dateModified":"2026-07-13T07:01:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python__new__\/"},"wordCount":1183,"commentCount":3,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python__new__\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-new-method-guide-pythonpool.png","keywords":["__new__ python","__new__ python 3","python __new__ arguments","python __new__ constructor","python __new__ example","python __new__ vs __init__","python class attributes __new__","python find __new__ examples"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python__new__\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/python__new__\/","url":"https:\/\/www.pythonpool.com\/python__new__\/","name":"Python __new__: Control Object Creation Before __init__","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python__new__\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python__new__\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-new-method-guide-pythonpool.png","datePublished":"2021-01-24T13:54:10+00:00","dateModified":"2026-07-13T07:01:33+00:00","description":"Understand Python __new__ versus __init__, immutable types, custom allocation, singleton patterns, cooperative inheritance, and safe object construction.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python__new__\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python__new__\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python__new__\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-new-method-guide-pythonpool.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-new-method-guide-pythonpool.png","width":1350,"height":650,"caption":"Python __new__ method object creation guide"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python__new__\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Python __new__: Control Object Creation Before __init__"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Practical Python tutorials, error fixes, code examples, and project guides.","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/664ced779ebbb8ddfd3c58a60d6f9d66","name":"Rohit Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c9a762a12f6bf9093f4c8a7643c0b6a17dd903d9602fae379649d1b050386b1a?s=96&d=wavatar&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c9a762a12f6bf9093f4c8a7643c0b6a17dd903d9602fae379649d1b050386b1a?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c9a762a12f6bf9093f4c8a7643c0b6a17dd903d9602fae379649d1b050386b1a?s=96&d=wavatar&r=g","caption":"Rohit Kumar"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/8080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=8080"}],"version-history":[{"count":39,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/8080\/revisions"}],"predecessor-version":[{"id":41558,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/8080\/revisions\/41558"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/34250"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=8080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=8080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=8080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}