Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65165

Re: __init__ is the initialiser

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'example:': 0.03; 'classes,': 0.05; 'explicitly': 0.05; 'stops': 0.07; '__init__': 0.09; 'arguments': 0.09; 'constructor': 0.09; 'derived': 0.09; 'english,': 0.09; 'immutable': 0.09; 'inherited': 0.09; 'lawrence': 0.09; 'method,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'jan': 0.12; '__init__,': 0.16; '__new__': 0.16; 'allocates': 0.16; 'builtins': 0.16; 'builtins.': 0.16; 'created.': 0.16; 'expression.': 0.16; 'initialiser': 0.16; 'initializes': 0.16; 'instance;': 0.16; 'mutable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'returned;': 0.16; 'right:': 0.16; 'runtime.': 0.16; 'torn': 0.16; 'wording': 0.16; 'so.': 0.16; 'wrote:': 0.18; 'any,': 0.19; 'passing': 0.19; 'foundation': 0.20; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "i'm": 0.30; 'that.': 0.31; 'usually': 0.31; 'doc': 0.31; 'object.': 0.31; 'raised': 0.31; 'class': 0.32; 'stuff': 0.32; 'url:python': 0.33; 'subject:the': 0.34; 'problem': 0.35; "can't": 0.35; 'classes': 0.35; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'reflect': 0.36; 'doing': 0.36; 'url:org': 0.36; 'should': 0.36; 'clear': 0.37; 'to:addr:python- list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'received:org': 0.40; 'called': 0.40; 'how': 0.40; 'ensure': 0.60; 'most': 0.60; 'url:3': 0.61; 'took': 0.61; 'received:173': 0.61; "you're": 0.61; 'first': 0.61; 'name': 0.63; 'temporary': 0.65; 'here': 0.66; 'sound': 0.68; 'special': 0.74; 'power': 0.76; '95%': 0.84; 'bare': 0.84; 'batchelder': 0.84; 'ethan': 0.84; 'furman': 0.84; 'received:fios.verizon.net': 0.84; 'url:datamodel': 0.84; 'url:html#object': 0.84; 'url:reference': 0.84; 'water.': 0.84; 'tied': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: __init__ is the initialiser
Date Fri, 31 Jan 2014 21:28:02 -0500
References <lcgtpf$tui$1@ger.gmane.org> <lcgut2$b8r$1@ger.gmane.org> <52EC0A86.7060102@stoneleaf.us>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding quoted-printable
X-Gmane-NNTP-Posting-Host pool-173-75-254-207.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
In-Reply-To <52EC0A86.7060102@stoneleaf.us>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6243.1391221704.18130.python-list@python.org> (permalink)
Lines 73
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391221705 news.xs4all.nl 2933 [2001:888:2000:d::a6]:38997
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65165

Show key headers only | View raw


On 1/31/2014 3:41 PM, Ethan Furman wrote:
> On 01/31/2014 11:52 AM, Ned Batchelder wrote:
>> On 1/31/14 2:33 PM, Mark Lawrence wrote:
>>>  From http://docs.python.org/3/reference/datamodel.html#object.__init__
>>> which states:-
>>>
>>> "
>>> Called when the instance is created. The arguments are those passed to
>>> the class constructor expression. If a base class has an __init__()
>>> method, the derived class’s __init__() method, if any, must explicitly
>>> call it to ensure proper initialization of the base class part of the
>>> instance; for example: BaseClass.__init__(self, [args...]). As a special
>>> constraint on constructors, no value may be returned; doing so will
>>> cause a TypeError to be raised at runtime.
>>> "
>>>
>>> Should the wording of the above be changed to clearly reflect that we
>>> have an initialiser here and that __new__ is the constructor?

Construct a house:
   Clear and grade house site.
   Bring in power and water.
   Built temporary structures.
   Built foundation.
   Built house on foundation.

For most classes, __new__ stops with the foundation -- the bare object 
object (with the class name slapped onto it). A *house* is not 
constructed until the house is constructed on top of the foundation.

>> I'm torn about that.  The fact is, that for 95% of the reasons you
>> want to say "constructor", the thing you're
>> describing is __init__.

Right: __init__ usually does the stuff that makes the object an instance 
of a particular class rather than just a bare bones object. In English, 
constructing a 'something' includes constructing the features that make 
the object a 'something' rather than something else.

>>>  Most classes have __init__, only very very few have __new__.

*Every* class has .__new__. Mutable builtins and almost all user classes 
inherit .__new__ from object. Every class also has .__init__, but it is 
mainly inherited from object by immutable builtins.
 >>> tuple.__init__
<slot wrapper '__init__' of 'object' objects>
User classes lacking .__init__ usually inherit it from something other 
than object. So objects are constructed by first calling .__new__ and 
then passing the result to .__init__. The Python 3 doc should say so.

> My problem is with the first sentence, as it makes it sound like there
> is no __new__ and everything you need is in __init__.

.__new__ allocates a bare object and initializes immutable builtins.

   Figuring out how
> __new__ and __init__ were tied together took a long time because of that.
>
>> Why can't we call __init__ the constructor and __new__ the allocator?

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: __init__ is the initialiser Terry Reedy <tjreedy@udel.edu> - 2014-01-31 21:28 -0500

csiph-web