This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients Jurko.Gospodnetić, docs@python, eryksun, steven.daprano
Date 2014-05-02.14:45:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1399041924.91.0.331581890518.issue21415@psf.upfronthosting.co.za>
In-reply-to
Content
> I believe that this explains why you have to use this idiom 
> inside __new__ when using super():
> 
>     def __new__(cls, x):
>         super().__new__(cls, x)

Yes, if __new__ is defined and is a function, type_new replaces it with a staticmethod:

http://hg.python.org/cpython/file/04f714765c13/Objects/typeobject.c#l2437

For example:

    >>> class A: __new__ = lambda c: 0

    >>> type(vars(A)['__new__'])
    <class 'staticmethod'>

A heap type that defines __new__ has tp_new set to slot_tp_new. This looks up and calls __new__, with the class inserted as the first argument:

http://hg.python.org/cpython/file/04f714765c13/Objects/typeobject.c#l6036

If you use a classmethod, looking up __new__ returns a method bound to the class. When called, this inserts the class in the args yet again:

http://hg.python.org/cpython/file/04f714765c13/Objects/classobject.c#l321
History
Date User Action Args
2014-05-02 14:45:24eryksunsetrecipients: + eryksun, steven.daprano, docs@python, Jurko.Gospodnetić
2014-05-02 14:45:24eryksunsetmessageid: <1399041924.91.0.331581890518.issue21415@psf.upfronthosting.co.za>
2014-05-02 14:45:24eryksunlinkissue21415 messages
2014-05-02 14:45:24eryksuncreate