What is the downside of using object.__new__ in __new__?
<p>Coding exception classes, I came across this error: </p>

<p><code>TypeError: object.__new__(A) is not safe, use Exception.__new__()</code></p>

<p>There's a similar question posted here:
<a href="http://stackoverflow.com/questions/12952184/typeerror-object-new-int-is-not-safe-use-int-new">TypeError: object.__new__(int) is not safe, use int.__new__()</a>. So <code>__new__</code> was deprecated for the following reason:</p>

<p><a href="https://mail.python.org/pipermail/python-dev/2008-February/076854.html" rel="nofollow">[Python-Dev] <code>__new__</code> deprecation</a></p>

<blockquote>
  <p>Guido van Rossum </p>
  
  <p><em>"The message means just what it says. :-) There's no point in calling
  <code>object.__new__()</code> with more than a class parameter, and any code that
  did so was just dumping those args into a black hole."</em></p>
</blockquote>

<p>But the warning in 3.3 that I get "is not safe" is scary. I try to understand the implication of using <code>object.__new__</code>, let's consider this example: </p>

<pre><code>&gt;&gt;&gt; class A(Exception):
...     def __new__(cls, *args):
...             return object.__new__(A)
...
&gt;&gt;&gt; A()
TypeError: object.__new__(A) is not safe, use Exception.__new__()
</code></pre>

<p>Fails miserably. Another Example: </p>

<pre><code>&gt;&gt;&gt; class A(object):
...     def __new__(cls, *args):
...             return object.__new__(A)
...
&gt;&gt;&gt;
&gt;&gt;&gt; A()
&lt;__main__.A object at 0x0000000002F2E278&gt;
</code></pre>

<p>works fine. Although, <code>object</code> is a builtin class just like <code>Exception</code> with respect to their roles, they share the trait of being builtin-classes. Now with <code>Exception</code>, the first example raises <code>TypeError</code>, but with <code>object</code>, it does not? </p>

<p><strong>(a) What are the downsides of using <code>object.__new__</code> that made Python to raise the error (<code>TypeError:...is not safe...</code>) in the first Example?</strong> </p>

<p><strong>(b) What sort of checking Python performs before to calling <code>__new__</code>? Or: What is the condition that makes Python raise the error in the first example?</strong> </p>

<p>There is no problem in calling <code>object.__new__</code>, but there is a problem in not calling <code>Exception.__new__</code>.</p>

<p><code>Exception</code> class was designed in such way that it is crucial that its <code>__new__</code> must be called, so it complains if that is not done.</p>

<p>There was a question why this happens only with built-in classes. Python in fact does it with every class which is programmed to do that.</p>

<p>Here is a simplified poor-mans implementation of the same mechanism in a custom class:</p>

<pre><code>class A(object):
    def __new__(cls):
        rtn = object.__new__(cls)
        rtn.new_called = True
        return rtn

    def __init__(self):
        assert getattr(self,'new_called',False), \
            "object.__new__ is unsafe, use A.__new__"

class B(A):
    def __new__(cls):
        return object.__new__(cls)
</code></pre>

<p>And now:</p>

<pre><code>&gt;&gt;&gt; A()
&lt;__main__.A object at 0x00000000025CFF98&gt;

&gt;&gt;&gt; B()
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "&lt;stdin&gt;", line 7, in __init__
AssertionError: object.__new__ is unsafe, use A.__new__
</code></pre>

<hr>

<p>As a side note, this example from the question actually has two errors:</p>

<pre><code>&gt;&gt;&gt; class A(Exception):
...     def __new__(cls, *args):
...             return object.__new__(A)
</code></pre>

<p>The first is that <code>__new__</code> is called on <code>object</code>, thus ignoring <code>Exception.__new__</code>.</p>

<p>The other, just as severe is that <code>A</code> is passed to <code>__new__</code> instead of <code>cls</code>, which hinders all classes inherited from <code>A</code>.</p>

<p>See this example:</p>

<pre><code>class A(object):
    def __new__(cls):
        return object.__new__(A)  # The same erroneous line, without Exception

class B(A):
    pass
</code></pre>

<p>And now <code>B()</code> does not create an instance of <code>B</code>:</p>

<pre><code>&gt;&gt;&gt; B()
&lt;__main__.A object at 0x00000000025D30B8&gt;
</code></pre>

python