[Python-3000] socket GC worries
Guido van Rossum
guido at python.org
Mon Oct 29 21:38:19 CET 2007
2007/10/29, Bill Janssen <janssen at parc.com>:
> > Actually, I'm still up for tweaks to the I/O model if it solves a real
> > problem, as long as most of the high-level APIs stay the same (there
> > simply is too much code that expects those to behave a certain way).
> >
> > I don't quite understand what you mean by inverted though.
>
> I'm actually thinking more in terms of avoiding future problems.
Can you remind me of what future problems again?
> I thought we'd discussed this a few months ago, but here it is again:
>
> I'd break up the BaseIO class into a small set of base classes, so that
> we can be more explicit about what a particular kind of I/O channel is
> or is not:
I see, static type checks in favor of dynamic behavior checks -- e.g.
isinstance(s, SeekableIOStream) rather than s.seekable(). If that's
all, I guess I already expressed earlier I don't really like that --
in practice I think the dynamic checks are more flexible, and the
class hierarchy you're proposing is hard to implement in C (where
unfortunately I'm restricted to single inheritance). E.g. depending on
how a program is invoked, sys.stdin may be seekable or it may not be.
--Guido
> (Please excuse typos, I'm generating this off-the-cuff -- does
> @abstract actually exist?)
>
> -------------------------------------------------------------
>
> class IOStream:
>
> @abstract
> def close(self):
>
> @property
> def closed(self):
>
> class InputIOStream (IOStream):
>
> @abstract
> def read(self, buffer=None, nbytes=None):
>
> class OutputIOStream (IOStream):
>
> @abstract
> def write(self, bytes):
>
> @abstract
> def flush(self):
>
> class SeekableIOStream (IOStream):
>
> @abstract
> def tell(self):
>
> @abstract
> def seek(self):
>
> @abstract
> def truncate(self):
>
> class SystemIOStream (IOStream):
>
> @property
> def fileno(self):
>
> @property
> def isatty (self):
>
> class TextInputStream (InputIOStream):
>
> @abstract
> def readline(self):
>
> @abstract
> def readlines(self):
>
> class TextOutputStream (InputIOStream):
>
> @abstract
> def readline(self):
>
> @abstract
> def readlines(self):
>
> class FileStream (SystemIOStream, SeekableIOStream):
>
> @property
> name
>
> @property
> mode
>
> # note that open() would return FileStream mixed with one or both of
> # {Text}InputStream and {Text}OutputStream, depending on the "mode".
>
> class StringIO (SeekableIOStream):
>
> # again, mixed with IO modes, depending on "mode".
>
> -------------------------------------------------------------
>
> I think of this as inverted, because it puts primitives like "read"
> and "write" at the lowest layers, not above things like "fileno" or
> "truncate", which are very specialized and should only apply to a
> subset of I/O channels.
>
> I realize that there are some practical problems with this; such as
> making _fileio.FileIO inherit from (multiple) Python base classes.
>
> Bill
>
>
>
>
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list