Path: csiph.com!feeder.erje.net!1.eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Random832 Newsgroups: comp.lang.python Subject: Re: def __init__(self): Date: Tue, 26 Apr 2016 12:26:07 -0400 Lines: 12 Message-ID: References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> <1461687967.2507874.590200129.102244C8@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de ex93OttTxfn4cHxNlLVGewRyPjpq5VkYfiMSXku22RgQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '(of': 0.07; 'override': 0.07; 'immutable': 0.09; 'instance.': 0.09; 'received:internal': 0.09; '(rather': 0.16; '__new__': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'overriding': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'subclassing': 0.16; 'subject:def': 0.16; 'wrote:': 0.16; 'python?': 0.18; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'define': 0.27; 'class': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'tue,': 0.34; 'instance': 0.35; 'possible': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'received:66': 0.38; 'to:addr:python.org': 0.40; 'header:Message- Id:1': 0.61; 'more': 0.63; '26,': 0.72; 'obvious': 0.76; 'construct': 0.84; 'subject:self': 0.84 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=z446C/2mRB374q7j59l7qo5jsPM=; b=xyXdy+ KMXHfCop5b99eydohXlEM2D5/xcWKBvnPMipyQMy0tDjGrc5R8Pm/g5F7I+adgNS XSNofOvXJpKMIXK9iOh+EUWHhJA1EsdyMzw4eJGwUMy2Wrz4ZlrQu55hDhTAP6x/ zFFhqJIfNvpEohoMjUER4kkv1m/4dWi3kppjI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=z446C/2mRB374q7 j59l7qo5jsPM=; b=DGIKAcPHtkUeYQxDhwi4M88R/U7pkDnXUhI4oI9GIJpESBV xQ4jxJ9IidWcuwlyjj6dlSuZ2uVKMm5YQnMcwz6cVYJijUivNfMKLzIc7NHKFYJ6 9VTVDx3f0OWTxLtOssr2xD5HC329A6opqBKgxZ6tQtmoN5yGGgHrkBMQ+MpA= X-Sasl-Enc: h16RJkcVvdN1d0eTmSO74GA3HXqZwcgu6fx+AzvS3QnT 1461687967 X-Mailer: MessagingEngine.com Webmail Interface - ajax-b462e126 In-Reply-To: <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <1461687967.2507874.590200129.102244C8@webmail.messagingengine.com> X-Mailman-Original-References: <34e51ef5-9679-40ec-bc8f-47981353e9d7@googlegroups.com> <571F1361.3010402@digipen.edu> <85eg9sn7qo.fsf@benfinney.id.au> <87lh40pyik.fsf@elektro.pacujo.net> <571f9362$0$1602$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:107666 On Tue, Apr 26, 2016, at 12:12, Steven D'Aprano wrote: > The obvious reason for overriding __new__ is to construct an immutable > instance. You have to override __new__, because by the time it returns > the > instance is immutable and you can no longer initialise it. Other than by subclassing an existing immutable type written in C, is it actually possible to define a truly-immutable (rather than contract-immutable) class in python? (Of course, subclassing immutable C types is the more obvious answer to when you have to override __new__).