From 109d57358e9078fb1139e2b7687d7e300ce4dcb4 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Sat, 7 Jul 2012 17:03:22 +0200 Subject: Issue #13248: io: Remove obsolete argument "max_buffer_size" of BufferedWriter and BufferedRWPair. --- Doc/library/io.rst | 7 ------- Lib/_pyio.py | 22 ++++------------------ Lib/test/test_io.py | 10 ++++------ Misc/NEWS | 3 +++ Modules/_io/bufferedio.c | 42 ++++++++++-------------------------------- 5 files changed, 21 insertions(+), 63 deletions(-) diff --git a/Doc/library/io.rst b/Doc/library/io.rst index 1d3d702..dd98a46 100644 --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -604,8 +604,6 @@ than raw I/O does. *raw* stream. If the *buffer_size* is not given, it defaults to :data:`DEFAULT_BUFFER_SIZE`. - A third argument, *max_buffer_size*, is supported, but unused and deprecated. - :class:`BufferedWriter` provides or overrides these methods in addition to those from :class:`BufferedIOBase` and :class:`IOBase`: @@ -631,8 +629,6 @@ than raw I/O does. in the first argument. If the *buffer_size* is omitted it defaults to :data:`DEFAULT_BUFFER_SIZE`. - A third argument, *max_buffer_size*, is supported, but unused and deprecated. - :class:`BufferedRandom` is capable of anything :class:`BufferedReader` or :class:`BufferedWriter` can do. @@ -647,9 +643,6 @@ than raw I/O does. writeable respectively. If the *buffer_size* is omitted it defaults to :data:`DEFAULT_BUFFER_SIZE`. - A fourth argument, *max_buffer_size*, is supported, but unused and - deprecated. - :class:`BufferedRWPair` implements all of :class:`BufferedIOBase`\'s methods except for :meth:`~BufferedIOBase.detach`, which raises :exc:`UnsupportedOperation`. diff --git a/Lib/_pyio.py b/Lib/_pyio.py index c06f4b8..1ce61e9 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -5,7 +5,6 @@ Python implementation of the io module. import os import abc import codecs -import warnings import errno # Import _thread instead of threading to reduce startup cost try: @@ -1065,19 +1064,13 @@ class BufferedWriter(_BufferedIOMixin): DEFAULT_BUFFER_SIZE. """ - _warning_stack_offset = 2 - - def __init__(self, raw, - buffer_size=DEFAULT_BUFFER_SIZE, max_buffer_size=None): + def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE): if not raw.writable(): raise IOError('"raw" argument must be writable.') _BufferedIOMixin.__init__(self, raw) if buffer_size <= 0: raise ValueError("invalid buffer size") - if max_buffer_size is not None: - warnings.warn("max_buffer_size is deprecated", DeprecationWarning, - self._warning_stack_offset) self.buffer_size = buffer_size self._write_buf = bytearray() self._write_lock = Lock() @@ -1167,15 +1160,11 @@ class BufferedRWPair(BufferedIOBase): # XXX The usefulness of this (compared to having two separate IO # objects) is questionable. - def __init__(self, reader, writer, - buffer_size=DEFAULT_BUFFER_SIZE, max_buffer_size=None): + def __init__(self, reader, writer, buffer_size=DEFAULT_BUFFER_SIZE): """Constructor. The arguments are two RawIO instances. """ - if max_buffer_size is not None: - warnings.warn("max_buffer_size is deprecated", DeprecationWarning, 2) - if not reader.readable(): raise IOError('"reader" argument must be readable.') @@ -1232,13 +1221,10 @@ class BufferedRandom(BufferedWriter, BufferedReader): defaults to DEFAULT_BUFFER_SIZE. """ - _warning_stack_offset = 3 - - def __init__(self, raw, - buffer_size=DEFAULT_BUFFER_SIZE, max_buffer_size=None): + def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE): raw._checkSeekable() BufferedReader.__init__(self, raw, buffer_size) - BufferedWriter.__init__(self, raw, buffer_size, max_buffer_size) + BufferedWriter.__init__(self, raw, buffer_size) def seek(self, pos, whence=0): if whence not in valid_seek_flags: diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 54ba179..ed8564c 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -1255,9 +1255,8 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests): self.assertRaises(IOError, bufio.tell) self.assertRaises(IOError, bufio.write, b"abcdef") - def test_max_buffer_size_deprecation(self): - with support.check_warnings(("max_buffer_size is deprecated", - DeprecationWarning)): + def test_max_buffer_size_removal(self): + with self.assertRaises(TypeError): self.tp(self.MockRawIO(), 8, 12) @@ -1313,9 +1312,8 @@ class BufferedRWPairTest(unittest.TestCase): pair = self.tp(self.MockRawIO(), self.MockRawIO()) self.assertRaises(self.UnsupportedOperation, pair.detach) - def test_constructor_max_buffer_size_deprecation(self): - with support.check_warnings(("max_buffer_size is deprecated", - DeprecationWarning)): + def test_constructor_max_buffer_size_removal(self): + with self.assertRaises(TypeError): self.tp(self.MockRawIO(), self.MockRawIO(), 8, 12) def test_constructor_with_not_readable(self): diff --git a/Misc/NEWS b/Misc/NEWS index 9334007..7b519d2 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -23,6 +23,9 @@ Core and Builtins Library ------- +- Issue #13248: Remove obsolete argument "max_buffer_size" of BufferedWriter + and BufferedRWPair, from the io module. + - Issue #13248: Remove obsolete argument "version" of argparse.ArgumentParser. - Issue #14814: implement more consistent ordering and sorting behaviour diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 21393a3..f717817 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -1759,15 +1759,6 @@ PyTypeObject PyBufferedReader_Type = { -static int -complain_about_max_buffer_size(void) -{ - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "max_buffer_size is deprecated", 1) < 0) - return 0; - return 1; -} - /* * class BufferedWriter */ @@ -1776,7 +1767,7 @@ PyDoc_STRVAR(bufferedwriter_doc, "\n" "The constructor creates a BufferedWriter for the given writeable raw\n" "stream. If the buffer_size is not given, it defaults to\n" - "DEFAULT_BUFFER_SIZE. max_buffer_size isn't used anymore.\n" + "DEFAULT_BUFFER_SIZE.\n" ); static void @@ -1789,23 +1780,18 @@ _bufferedwriter_reset_buf(buffered *self) static int bufferedwriter_init(buffered *self, PyObject *args, PyObject *kwds) { - /* TODO: properly deprecate max_buffer_size */ - char *kwlist[] = {"raw", "buffer_size", "max_buffer_size", NULL}; + char *kwlist[] = {"raw", "buffer_size", NULL}; Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE; - Py_ssize_t max_buffer_size = -234; PyObject *raw; self->ok = 0; self->detached = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|nn:BufferedReader", kwlist, - &raw, &buffer_size, &max_buffer_size)) { + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:BufferedReader", kwlist, + &raw, &buffer_size)) { return -1; } - if (max_buffer_size != -234 && !complain_about_max_buffer_size()) - return -1; - if (_PyIOBase_check_writable(raw, Py_True) == NULL) return -1; @@ -2186,16 +2172,12 @@ bufferedrwpair_init(rwpair *self, PyObject *args, PyObject *kwds) { PyObject *reader, *writer; Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE; - Py_ssize_t max_buffer_size = -234; - if (!PyArg_ParseTuple(args, "OO|nn:BufferedRWPair", &reader, &writer, - &buffer_size, &max_buffer_size)) { + if (!PyArg_ParseTuple(args, "OO|n:BufferedRWPair", &reader, &writer, + &buffer_size)) { return -1; } - if (max_buffer_size != -234 && !complain_about_max_buffer_size()) - return -1; - if (_PyIOBase_check_readable(reader, Py_True) == NULL) return -1; if (_PyIOBase_check_writable(writer, Py_True) == NULL) @@ -2420,28 +2402,24 @@ PyDoc_STRVAR(bufferedrandom_doc, "\n" "The constructor creates a reader and writer for a seekable stream,\n" "raw, given in the first argument. If the buffer_size is omitted it\n" - "defaults to DEFAULT_BUFFER_SIZE. max_buffer_size isn't used anymore.\n" + "defaults to DEFAULT_BUFFER_SIZE.\n" ); static int bufferedrandom_init(buffered *self, PyObject *args, PyObject *kwds) { - char *kwlist[] = {"raw", "buffer_size", "max_buffer_size", NULL}; + char *kwlist[] = {"raw", "buffer_size", NULL}; Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE; - Py_ssize_t max_buffer_size = -234; PyObject *raw; self->ok = 0; self->detached = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|nn:BufferedReader", kwlist, - &raw, &buffer_size, &max_buffer_size)) { + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:BufferedReader", kwlist, + &raw, &buffer_size)) { return -1; } - if (max_buffer_size != -234 && !complain_about_max_buffer_size()) - return -1; - if (_PyIOBase_check_seekable(raw, Py_True) == NULL) return -1; if (_PyIOBase_check_readable(raw, Py_True) == NULL) -- cgit v0.12