<br><br><div class="gmail_quote">On Sun, Apr 5, 2009 at 3:54 PM, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">Antoine Pitrou wrote:<br>
> James Y Knight <foom <at> <a href="http://fuhm.net" target="_blank">fuhm.net</a>> writes:<br>
>> It seems that a separate method "_internal_close" should've been<br>
>> defined to do the actual closing of the file, and the close() method<br>
>> should've been defined on the base class as "self.flush();<br>
>> self._internal_close()" and never overridden.<br>
><br>
> I'm completely open to changes as long as there is a reasonable consensus around<br>
> them. Your proposal looks sane, although the fact that a semi-private method<br>
> (starting with an underscore) is designed to be overriden in some classes is a<br>
> bit annoying.<br>
<br>
</div>Note that we already do that in a couple of places where it makes sense<br>
- in those cases the underscore is there to tell *clients* of the class<br>
"don't call this directly", but it is still explicitly documented as<br>
part of the subclassing API.<br>
<br>
(the only example I can find at the moment is in asynchat, but I thought<br>
there were a couple of more common ones than that - hopefully I'll think<br>
of them later)<br></blockquote></div><br><div>Queue.Queue in 2.* (and queue.Queue in 3.*) is like that too -- the single leading underscore meaning "protected" ("I'm here for subclasses to override me, only" in C++ parlance) and a great way to denote "hook methods" in a Template Method design pattern instance. Base class deals with all locking issues in e.g. 'get' (the method a client calls), subclass can override _get and not worry about threading (it will be called by parent class's get with proper locks held and locks will be properly released &c afterwards).</div>
<div><br></div><div><br></div><div>Alex</div>