X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 78.192.65.63 Path: csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!news.muarf.org!news.roellig-ltd.de!open-news-network.org!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed4a.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'init': 0.07; 'python3': 0.07; '*args,': 0.09; '__init__': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'args,': 0.16; 'none.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:object': 0.16; 'subject:skip:m 10': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'andrew': 0.30; '>>>>': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'but': 0.35; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'new': 0.61 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Basic misunderstanding on object creation Date: Wed, 13 May 2015 16:55:31 +0200 Organization: None References: <25ba3a96-21ee-4a83-b7c1-8ac60508d30c@googlegroups.com> <06301cb8-39a6-410b-9fad-afe6bd4d3217@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd8b68.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431528943 news.xs4all.nl 2917 [2001:888:2000:d::a6]:57208 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90559 andrew cooke wrote: >> But then nothing will be passed to __init__ on the subclass. >> >> Andrew > >>>> class Foo: > ... def __new__(cls, *args, **kargs): > ... print('new', args, kargs) > ... super().__new__(cls) > ... >>>> class Bar(Foo): > ... def __init__(self, a): > ... print('init', a) > ... >>>> Bar(1) > new (1,) {} > > no "init" is printed. That's because yor __new__() returns None. Try $ cat new_demo.py class Foo: def __new__(cls, *args, **kargs): print('new', cls, args, kargs) return super().__new__(cls) class Bar(Foo): def __init__(self, a): print('init', a) bar = Bar(42) $ python3 new_demo.py new (42,) {} init 42 $