Path: csiph.com!news.mixmin.net!news2.arglkargh.de!news.karotte.org!fu-berlin.de!uni-berlin.de!not-for-mail From: eryk sun Newsgroups: comp.lang.python Subject: Re: What arguments are passed to the __new__ method ? Date: Tue, 1 Mar 2016 15:09:14 -0600 Lines: 24 Message-ID: References: <56d5d043$0$632$426a74cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de v8pG5Fumdz9nYI3ojVjcPATjgrQGczxnGv++04Uh8dmQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'args': 0.04; 'cpython': 0.05; '1000.': 0.09; 'ast': 0.09; 'subject:method': 0.09; 'def': 0.13; 'ignore': 0.14; '2016': 0.16; 'bytecode': 0.16; 'ignores': 0.16; 'kwds': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; "type's": 0.16; 'wrote:': 0.16; 'passes': 0.18; 'language': 0.19; 'arguments': 0.22; 'function,': 0.22; 'ok.': 0.22; 'pass': 0.22; 'header:In- Reply-To:1': 0.24; 'subject: ?': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'callable': 0.29; 'handled': 0.29; 'skip:_ 10': 0.32; 'class': 0.33; 'message.': 0.33; 'case,': 0.34; 'tue,': 0.34; 'previous': 0.34; 'received:google.com': 0.35; 'should': 0.36; 'received:209.85': 0.36; 'cases': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'received:209': 0.38; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'still': 0.40; 'mar': 0.65; 'matter.': 0.66; 'premiere': 0.84; 'inheritance,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=AOl4U6sSGSPEJ4CEsCXm/7LOdCjhbeAfauLByRpMAJU=; b=x/uctIAsCXUIC1/LYoz/bMxIlt0NIa/itixBrN/UJT/8Rdt6aJ3kwJS1MZP4qxGHoM v+efIzQUccryCYHgwGRxzADGd75s3JNdiFRQeBA22Y0RyhsawVwOZsBaC+kHZOEvhpPl saRiVZY0WHwstQW7tBl3Di9Irt47MHICwD/MXZ/ZWuEqX/PzS7qXTdRwbWPnMwHd73L/ FcOd7WdSCERM0IFtQsbfV/iCiltj0r6MAHS3eV6msxCgEsmjbWc4Ja94vbnMnGrDdJlt N6zI82WUZzawsB7rohkuJG9SsJSaO5w84sa1PUOkPwytWR2Jq8Iw4jqgdaH7rHdkzj/E 2iKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=AOl4U6sSGSPEJ4CEsCXm/7LOdCjhbeAfauLByRpMAJU=; b=W2Ku9nMyQ6gJcgb2lObafqACevD4eNvXMRKFEamE+je4sWMkEtv1jFtq4IILwi3+1Z AS5bx7k8if7ukBxJJq1PpcP4FEFbe+FDlvqBjwuh4GDncvdhe2IMHAZR1dOKwRv8C7bU eFKghWlNg6gNbyRuoD7ucwXQccS1b0gMLr+LtJ+DY3DtlBWEGKnZY7PJcX1BsfT8h2hj j1jwPsFbCq2k6GAOpaqN6LZ80qCEOxxDOyudsUSa7BzfcEEnBNvWr6E3q8QTrSKzrc10 uRkBNHe1cUoYTJAaR9GJ6PBxYzUu8lanv1U0FEk+pzfP2KJhGcZN81WDb/4xk0JadfV2 n6IA== X-Gm-Message-State: AD7BkJJxumFfG8pgOlEWY8EuHDyfzMaOoD7PZZCcVMkbWnwobHu9U0eOa8vtdybNJCtB+1D2uXDGFQqsWHGnsA== X-Received: by 10.107.14.209 with SMTP id 200mr1474808ioo.73.1456866594469; Tue, 01 Mar 2016 13:09:54 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:103821 On Tue, Mar 1, 2016 at 2:27 PM, Terry Reedy 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.