This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.pipe() should return a structsequence (or namedtuple.)
Type: enhancement Stage: patch review
Components: IO Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Rosuav, christian.heimes, jonathan.slenders, martin.panter, yselivanov
Priority: normal Keywords: patch

Created on 2015-06-30 07:19 by jonathan.slenders, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
ospipe.patch yselivanov, 2015-07-01 03:16 review
Messages (11)
msg245980 - (view) Author: Jonathan Slenders (jonathan.slenders) * Date: 2015-06-30 07:19
As discussed on python-ideas, os.pipe should return a structsequence instead of a plain tuple.

To be decided is the naming for the read and write end.
Personally, I'm in favour of using readfd/writefd.

> our_pipe = pipe()
> os.write(our_pipe.writefd, b'data')
> os.read(our_pipe.readfd, 1024)
msg245981 - (view) Author: Chris Angelico (Rosuav) * Date: 2015-06-30 07:30
Another good option is read/write without the 'fd' suffix. Either works, I'd prefer the shorter one but by a small margin.
msg245991 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-06-30 14:52
'read'/'write' is sufficient.

+1 for the proposal.
msg245992 - (view) Author: Jonathan Slenders (jonathan.slenders) * Date: 2015-06-30 14:57
Niki Spahiev made a valid argument saying that the following code is common:

if not hasattr(src, 'read'): src = open(src)

This will break if we name it 'read'/'write'  like the methods of a file object.
msg246011 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-07-01 01:33
+1 for readfd/writefd.  I think 'fd' suffix is necessary to make it explicit that those aren't file objects.
msg246023 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-07-01 03:16
Here's a patch, please review.
msg246026 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-07-01 06:56
Nowhere else in the stdlib is 'readfd' defined, and 'writefd' is only used once in a test.

I think tacking on the 'fd' is both too low level as well as misleading since these are not file descriptors.

If there is no agreement on read/write (understandable since those are usually methods), then perhaps input/output?
msg246027 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-07-01 06:57
Okay, scratch the "not file descriptors" part of my comment, but the rest still stands.
msg246028 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-07-01 07:18
As for Niki's example:
---------------------
--> src = os.pipe()
--> src
(3, 4)
--> if not hasattr(src, 'read'): src = open(src)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: invalid file: (3, 4)
------------------------------------------------

This fails now.  If they pass a pipe tuple into the new code they'll just get a different error somewhere else, which seems fine to me.
msg246885 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-07-18 05:07
The original Python-ideas thread: <https://www.marc.info/?t=143558954500004>

If you want shorter field names, how about just r and w (as they are currently documented)?

os.write(our_pipe.w, b"data")
os.read(our_pipe.r, 1024)

“Input” and “output” would also work for me (though I am also happy with read, read_fd, etc). However it does seem a bit novel; in my experience people tend to say pipes have read and write ends, not inputs and outputs.

os.write(our_pipe.input, b"data")
os.read(our_pipe.output, 1024)
msg276948 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2016-09-19 06:30
In C programming common names for both ends are reader and writer. We could go with the pipes analogy and call the ends inlet and outlet.
History
Date User Action Args
2022-04-11 14:58:18adminsetgithub: 68724
2016-09-19 06:30:21christian.heimessetnosy: + christian.heimes
messages: + msg276948
2015-07-21 07:03:12ethan.furmansetnosy: - ethan.furman
2015-07-18 05:07:52martin.pantersettype: enhancement

messages: + msg246885
nosy: + martin.panter
2015-07-01 07:18:10ethan.furmansetmessages: + msg246028
2015-07-01 06:57:39ethan.furmansetmessages: + msg246027
2015-07-01 06:56:19ethan.furmansetmessages: + msg246026
2015-07-01 03:16:11yselivanovsetfiles: + ospipe.patch
keywords: + patch
messages: + msg246023

stage: patch review
2015-07-01 01:33:36yselivanovsetnosy: + yselivanov
messages: + msg246011
2015-06-30 14:57:17jonathan.slenderssetmessages: + msg245992
2015-06-30 14:52:10ethan.furmansetnosy: + ethan.furman
messages: + msg245991
2015-06-30 07:31:00Rosuavsetnosy: + Rosuav
messages: + msg245981
2015-06-30 07:19:17jonathan.slenderscreate