Re: [Python-Dev] Possible py3k io wierdness

2009-04-12 Thread Brian Quinlan
I've added a new proposed patch to: http://bugs.python.org/issue5700 The idea is: - only IOBase implements close() (though a subclass can override close without causing problems so long as it calls super().close() or calls .flush() and ._close() directly) - change IOBase.close to call .flush(

Re: [Python-Dev] Possible py3k io wierdness

2009-04-06 Thread Brian Quinlan
Nick Coghlan wrote: Brian Quinlan wrote: - you need the cooperation of your subclasses i.e. they must call super().flush() in .flush() to get correct close behavior (and this represents a backwards-incompatible semantic change) Are you sure about that? Going by the current _pyio semantics

Re: [Python-Dev] Possible py3k io wierdness

2009-04-06 Thread Nick Coghlan
Brian Quinlan wrote: > - you need the cooperation of your subclasses i.e. they must call > super().flush() in .flush() to get correct close behavior (and this > represents a backwards-incompatible semantic change) Are you sure about that? Going by the current _pyio semantics that Antoine poste

Re: [Python-Dev] Possible py3k io wierdness

2009-04-06 Thread Nick Coghlan
Alex Martelli wrote: > 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. Bas

Re: [Python-Dev] Possible py3k io wierdness

2009-04-05 Thread Brian Quinlan
James Y Knight wrote: On Apr 5, 2009, at 6:29 AM, Antoine Pitrou wrote: Brian Quinlan sweetapp.com> writes: I don't see why this is helpful. Could you explain why _RawIOBase.close() calling self.flush() is useful? I could not explain it for sure since I didn't write the Python version. I

Re: [Python-Dev] Possible py3k io wierdness

2009-04-05 Thread Greg Ewing
Antoine Pitrou wrote: Your proposal looks sane, although the fact that a semi-private method (starting with an underscore) is designed to be overriden in some classes is a bit annoying. The only other way I can see is to give up any attempt in the base class to ensure that flushing occurs befor

Re: [Python-Dev] Possible py3k io wierdness

2009-04-05 Thread Alex Martelli
On Sun, Apr 5, 2009 at 3:54 PM, Nick Coghlan wrote: > Antoine Pitrou wrote: > > James Y Knight fuhm.net> writes: > >> It seems that a separate method "_internal_close" should've been > >> defined to do the actual closing of the file, and the close() method > >> should've been defined on the base

Re: [Python-Dev] Possible py3k io wierdness

2009-04-05 Thread Nick Coghlan
Antoine Pitrou wrote: > James Y Knight fuhm.net> writes: >> It seems that a separate method "_internal_close" should've been >> defined to do the actual closing of the file, and the close() method >> should've been defined on the base class as "self.flush(); >> self._internal_close()" and ne

Re: [Python-Dev] Possible py3k io wierdness

2009-04-05 Thread Greg Ewing
Brian Quinlan wrote: if not self.__closed: try: -self.flush() +IOBase.flush(self) except IOError: pass # If flush() fails, just give up self.__closed = True That doesn't seem like a good idea to me at

Re: [Python-Dev] Possible py3k io wierdness

2009-04-05 Thread Antoine Pitrou
James Y Knight fuhm.net> writes: > > It seems that a separate method "_internal_close" should've been > defined to do the actual closing of the file, and the close() method > should've been defined on the base class as "self.flush(); > self._internal_close()" and never overridden. I'm comp

Re: [Python-Dev] Possible py3k io wierdness

2009-04-05 Thread James Y Knight
On Apr 5, 2009, at 6:29 AM, Antoine Pitrou wrote: Brian Quinlan sweetapp.com> writes: I don't see why this is helpful. Could you explain why _RawIOBase.close() calling self.flush() is useful? I could not explain it for sure since I didn't write the Python version. I suppose it's so that

Re: [Python-Dev] Possible py3k io wierdness

2009-04-05 Thread Brian Quinlan
Antoine Pitrou wrote: Brian Quinlan sweetapp.com> writes: I don't see why this is helpful. Could you explain why _RawIOBase.close() calling self.flush() is useful? I could not explain it for sure since I didn't write the Python version. I suppose it's so that people who only override flush()

Re: [Python-Dev] Possible py3k io wierdness

2009-04-05 Thread Antoine Pitrou
Brian Quinlan sweetapp.com> writes: > > I don't see why this is helpful. Could you explain why > _RawIOBase.close() calling self.flush() is useful? I could not explain it for sure since I didn't write the Python version. I suppose it's so that people who only override flush() automatically get

Re: [Python-Dev] Possible py3k io wierdness

2009-04-05 Thread Brian Quinlan
Hey Antoine, Thanks for the clarification! I see that the C implementation matches the Python implementation but I don't see how the semantics of either are useful in this case. If a subclass implements flush then, as you say, it must also implement close and call flush itself before calling

Re: [Python-Dev] Possible py3k io wierdness

2009-04-04 Thread Antoine Pitrou
Hi! sweetapp.com> writes: > > class _RawIOBase(_FileIO): FileIO is a subclass of _RawIOBase, not the reverse: >>> issubclass(_io._RawIOBase, _io.FileIO) False >>> issubclass(_io.FileIO, _io._RawIOBase) True I do understand your surprise, but the Python implementation of IOBase.close() in _pyi

[Python-Dev] Possible py3k io wierdness

2009-04-04 Thread brian
Hey, I noticed that the call pattern of the C-implemented io libraries is as follows (translating from C to Python): class _FileIO(object): def flush(self): if self.__IOBase_closed: raise ... def close(self): self.flush() self.__IOBase_closed = True class _RawIOBase(_FileI