Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!feeder1.xsusenet.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail 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; '(at': 0.04; 'parameters': 0.04; 'wednesday,': 0.07; '*args,': 0.09; '__init__': 0.09; 'def': 0.12; '15:25': 0.16; '__new__': 0.16; 'args,': 0.16; 'arguments:': 0.16; 'called,': 0.16; "object's": 0.16; 'object()': 0.16; 'subject:object': 0.16; 'subject:skip:m 10': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'result.': 0.19; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'andrew': 0.30; 'message-id:@mail.gmail.com': 0.30; '"",': 0.31; '13,': 0.31; '>>>>': 0.31; 'object.': 0.31; 'parameters.': 0.31; 'file': 0.32; 'class': 0.32; '(most': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'new': 0.61; 'thomas': 0.65; '2015': 0.84; 'rachel': 0.84 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 :content-type; bh=5nLIy+neW0dPqQc5ZCXBVzVGutXBdx/9mhUDfjKJWJM=; b=nflCuxAcFhAkg7oy7URinO5y232E4iJkVDbk5lwSL8BSurimhxyj94/dBHjr5WrAqE yxEljF16MCe0NK3ffAWjuAea9GVJ4uB0s7u5TCYHU+JsPOw5Me2hG3m7LIplAtnBrL5b zw6i2WhLtA4fLrlxvcHOewPlvNjjrR0GER/RgEVlFJSUAUkhVGJ8x5BIlsVM3O1hYBqN zMKCeDezCNsmEq9nwoCosdDKusqOrKz1YJyrv2nxRJQSCRtinS6Q5TLcbV0IpKQuOhC2 zyaLaC54an/rTSZcPtRwoXYzF+c7/H3hm8548aLhE73pE2ODCNs6m9Q0h4ALF7Y58V6/ laoQ== X-Received: by 10.42.226.8 with SMTP id iu8mr9309901icb.17.1431528908694; Wed, 13 May 2015 07:55:08 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <06301cb8-39a6-410b-9fad-afe6bd4d3217@googlegroups.com> References: <25ba3a96-21ee-4a83-b7c1-8ac60508d30c@googlegroups.com> <06301cb8-39a6-410b-9fad-afe6bd4d3217@googlegroups.com> From: Ian Kelly Date: Wed, 13 May 2015 08:54:28 -0600 Subject: Re: Basic misunderstanding on object creation To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431528916 news.xs4all.nl 2845 [2001:888:2000:d::a6]:56672 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90560 On Wed, May 13, 2015 at 8:42 AM, andrew cooke wrote: > On Wednesday, 13 May 2015 11:36:12 UTC-3, Thomas Rachel wrote: >> Am 13.05.2015 um 15:25 schrieb andrew cooke: >> >> >>>> class Foo: >> > ... def __new__(cls, *args, **kargs): >> > ... print('new', args, kargs) >> > ... super().__new__(cls, *args, **kargs) >> >> > new (1,) {} >> > Traceback (most recent call last): >> > File "", line 1, in >> > File "", line 4, in __new__ >> > TypeError: object() takes no parameters >> >> object's __new__() dosn't take any parameters. So call it without arguments: >> >> class Foo: >> def __new__(cls, *args, **kargs): >> print('new', args, kargs) >> super().__new__(cls) >> >> (at least if we know that we inherit from object. Might be that this one >> doesn't work very good with multiple inheritance...) >> >> >> Thomas > > But then nothing will be passed to __init__ on the subclass. __init__ is not called by __new__. In the object construction, __new__ is called, and *then* __init__ is called on the result.