On 01/09/2018 08:27 AM, Chris Angelico wrote:
On Tue, Jan 9, 2018 at 11:12 PM, Random832 <random...@fastmail.com> wrote:
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.


Only in POSIX. On other platforms, sockets are most definitely NOT
files. And datagram sockets don't really make sense to iterate over.

Part of the problem with even POSIX stream sockets (either TCP or Unix
domain) is what you do when there's nothing to read. Do you block,
waiting for a line? Do you raise StopIteration and then subsequently
become un-finished again (which, according to Python semantics, is a
broken iterator)?

This. Although it is technically broken, this is how reading from the console works. I believe that falls under practicality beats purity. ;)

--
~Ethan~

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to