[Python-ideas] make Connections iterable

Random832 random832 at fastmail.com
Tue Jan 9 07:12:25 EST 2018

On Tue, Jan 9, 2018, at 05:46, Nick Coghlan wrote:
> If you view them as comparable to subprocess pipes, then it can be
> surprising that they're not iterable when using a line-oriented
> protocol.
> If you instead view them as comparable to socket connections, then the
> lack of iteration support seems equally reasonable.

Sockets are files - there's no fundamental reason a stream socket using a line-oriented protocol (which is a common enough case), or a datagram socket, shouldn't be iterable. Why aren't they? Making sockets iterable would be a separate discussion, but I don't think this is necessarily an argument.

And saying "I think you should be handling errors in some particular way, so we'll make the API more difficult to encourage this" seems a non-sequitur. The whole point of exceptions is that the error handling code doesn't need to be directly at the point of use but can be, say, a try/catch wrapped around the inner loop.

More information about the Python-ideas mailing list