What arguments are passed to the __new__ method ?

eryk sun eryksun at gmail.com
Tue Mar 1 16:09:14 EST 2016


On Tue, Mar 1, 2016 at 2:27 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 3/1/2016 12:24 PM, ast wrote:
>
>> class Premiere:
>>     def __init__(self, price):
>>          pass
>> p = Premiere(1000)
>>
>> which is OK.
>
> Premiere is callable because it inherits object.__call__.  That function, or
> the implementation of the CALL FUNCTION bytecode, must notice that
> Premiere.__new__ is object.__new__, by inheritance, and only pass Premiere
> and not 1000.

It's not handled in bytecode or __call__. In CPython the type_call
function passes its args and kwds to the type's tp_new and tp_init
functions without modification. object.__new__ ignores the excess
arguments in this case, as described in my previous message.

While I think the cases where object.__new__ and object.__init__
ignore excess arguments are practical and sensible, they should still
be documented. AFAICT, the language reference has nothing to say on
this matter.



More information about the Python-list mailing list