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: Improve os.readv() and os.writev() documentation and docstring
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: benjamin.peterson, docs@python, ethan.furman, nikratio, python-dev, r.david.murray
Priority: normal Keywords: patch

Created on 2013-04-21 21:24 by nikratio, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue17811.patch nikratio, 2014-01-08 05:45
issue17811_rev2.patch nikratio, 2014-01-18 23:06 review
Messages (8)
msg187526 - (view) Author: Nikolaus Rath (nikratio) * Date: 2013-04-21 21:24
The os.writev and os.readv functions are currently documented as:

os.writev(fd, buffers)

    Write the contents of buffers to file descriptor fd, where buffers is an arbitrary sequence of buffers. Returns the total number of bytes written.

os.readv(fd, buffers)

    Read from a file descriptor into a number of writable buffers. buffers is an arbitrary sequence of writable buffers. Returns the total number of bytes read.


This is rather confusing, mostly because it's not clear what can be passed as *buffer* (since buffer objects don't exist in Python 3 anymore), and (as a consequence) how the input will be distributed among the list of buffers.

Reading the code, it seems to me that any object that implements the buffer protocol would be fine, but that still doesn't help much in practice. From the memoryview documentation, I can infer that `bytes` implements the buffer protocol, but is also immutable, so how can something be written into it?

I'd be happy to write a patch to the documentation, but someone would need to explain to me first what kind of buffers are actually acceptable (and I suspect this will be different for readv and writev).
msg187528 - (view) Author: Nikolaus Rath (nikratio) * Date: 2013-04-21 21:34
Here's a first attempt at improvement based on my guess:

os.writev(fd, buffers)

    Write the contents of buffers to file descriptor fd, where buffers is an arbitrary sequence of buffers. In this context, a buffer may be any Python object that provides a Memory View, i.e. that may be used to instantiate a `memoryview` object (e.g. a bytes or bytearray object). writev writes the contents of each memory view to the file descriptor and returns the total number of bytes written.

os.readv(fd, buffers)

    Read from a file descriptor into a number of writable buffers. buffers is an arbitrary sequence of writable buffers. In this context, a buffer may be any Python object that provides a writeable Memory View, i.e. that may be used to instantiate a `memoryview` object whose `read_only` attribute is false (for example, a bytearray object). Writeable memory views have a fixed size, and readv will transfer data into each buffer until it is full and then move on to the next buffer in the sequence to hold the rest of the data. readv returns the total number of bytes read (which may be less than the total capacity of all the buffers).
msg187530 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-04-21 21:44
Well, the documentation is technically precise.  I'd even managed to forget that buffer objects existed in Python2 :)

As you observed, in Python3 a buffer is something that implements the buffer protocol.  What I would do is link the word 'buffer' to http://docs.python.org/3/c-api/buffer.html.  Perhaps mentioning bytes and bytearray as examples of read-only and writeable buffers would be worthwhile, but they are mentioned in the first paragraph of that section so it may not be necessary.
msg187531 - (view) Author: Nikolaus Rath (nikratio) * Date: 2013-04-21 21:53
What section do you mean? bytearray is not mentioned anywhere in
http://docs.python.org/3.4/library/os.html.

I think the problem with just linking to the C API section is that it doesn't help people that are only using pure Python. You can't look at a Python object and tell whether it implements the buffer protocol or not. Therefore, I think it would be important to give at least a reference to memoryview as the Python equivalent of the buffer protocol.
msg207670 - (view) Author: Nikolaus Rath (nikratio) * Date: 2014-01-08 05:45
I have attached a patch that takes into account your comments. Would this be suitable for inclusion?
msg208386 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2014-01-18 05:21
IMO, it should just refer to the glossary entry for "bytes-like object".
msg208423 - (view) Author: Nikolaus Rath (nikratio) * Date: 2014-01-18 23:06
Indeed, this makes most sense. I didn't know that glossary entry existed. I have attached an updated patch. Thanks for reviewing!
msg208438 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-01-19 03:57
New changeset 8b413f813a13 by Benjamin Peterson in branch '3.3':
improve description of buffers argument for readv/writev (closes #17811)
http://hg.python.org/cpython/rev/8b413f813a13

New changeset 4d56006133f1 by Benjamin Peterson in branch 'default':
merge 3.3 (#17811)
http://hg.python.org/cpython/rev/4d56006133f1
History
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 62011
2014-01-19 03:57:55python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg208438

resolution: fixed
stage: resolved
2014-01-18 23:06:23nikratiosetversions: - Python 3.5
2014-01-18 23:06:06nikratiosetfiles: + issue17811_rev2.patch

messages: + msg208423
2014-01-18 05:21:04benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg208386
2014-01-18 02:50:03ethan.furmansetnosy: + ethan.furman
2014-01-08 05:45:55nikratiosetfiles: + issue17811.patch
keywords: + patch
messages: + msg207670
2013-04-21 21:53:22nikratiosetmessages: + msg187531
2013-04-21 21:44:15r.david.murraysetnosy: + r.david.murray
messages: + msg187530
2013-04-21 21:34:51nikratiosetmessages: + msg187528
2013-04-21 21:24:28nikratiocreate