summaryrefslogtreecommitdiffstats
path: root/Lib/_pyio.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-06-03 05:59:20 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-06-03 05:59:20 (GMT)
commitc9813d83f78c1eed12aebc286d6df0e9a5d90d04 (patch)
treead5967e5bcc619be26198efbf78502578e5da615 /Lib/_pyio.py
parent9aabaccb7632a35da37b3d9c58b6ee0aab3ac547 (diff)
downloadcpython-c9813d83f78c1eed12aebc286d6df0e9a5d90d04.zip
cpython-c9813d83f78c1eed12aebc286d6df0e9a5d90d04.tar.gz
cpython-c9813d83f78c1eed12aebc286d6df0e9a5d90d04.tar.bz2
Issue #20699: Document that “io” methods should accept memoryview
This matches the usage by BufferedReader, BufferedWriter, etc. Also document and test that the write() methods should only access their argument before they return.
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r--Lib/_pyio.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index ccd6ce8..11348b2 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -277,8 +277,9 @@ class IOBase:
may raise a IOError when operations they do not support are called.
The basic type used for binary data read from or written to a file is
- bytes. bytearrays are accepted too, and in some cases (such as
- readinto) needed. Text I/O classes work with str data.
+ the bytes type. Method arguments may also be bytearray or memoryview of
+ arrays of bytes. In some cases, such as readinto, a writable object such
+ as bytearray is required. Text I/O classes work with unicode data.
Note that calling any method (even inquiries) on a closed stream is
undefined. Implementations may raise IOError in this case.
@@ -649,7 +650,6 @@ class BufferedIOBase(IOBase):
Raises BlockingIOError if the underlying raw stream has no
data at the moment.
"""
- # XXX This ought to work with anything that supports the buffer API
data = self.read(len(b))
n = len(data)
try:
@@ -664,8 +664,7 @@ class BufferedIOBase(IOBase):
def write(self, b):
"""Write the given buffer to the IO stream.
- Return the number of bytes written, which is never less than
- len(b).
+ Return the number of bytes written, which is always len(b).
Raises BlockingIOError if the buffer is full and the
underlying raw stream cannot accept more data at the moment.