#2355: py3k warning for buffer().

This commit is contained in:
Georg Brandl 2008-03-25 07:56:27 +00:00
parent aef3e529e2
commit 80055f6295
3 changed files with 13 additions and 1 deletions

View file

@ -118,6 +118,11 @@ class TestPy3KWarnings(unittest.TestCase):
with catch_warning() as w: with catch_warning() as w:
self.assertWarning(set(), w, expected) self.assertWarning(set(), w, expected)
def test_buffer(self):
expected = 'buffer will be removed in 3.x'
with catch_warning() as w:
self.assertWarning(buffer('a'), w, expected)
def test_main(): def test_main():
run_unittest(TestPy3KWarnings) run_unittest(TestPy3KWarnings)

View file

@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 2?
Core and builtins Core and builtins
----------------- -----------------
- Issue #2355: add Py3k warning for buffer().
- Issue #1477: With narrow Unicode builds, the unicode escape sequence - Issue #1477: With narrow Unicode builds, the unicode escape sequence
\Uxxxxxxxx did not accept values outside the Basic Multilingual Plane. This \Uxxxxxxxx did not accept values outside the Basic Multilingual Plane. This
affected raw unicode literals and the 'raw-unicode-escape' codec. Now affected raw unicode literals and the 'raw-unicode-escape' codec. Now

View file

@ -229,6 +229,11 @@ PyBuffer_New(Py_ssize_t size)
static PyObject * static PyObject *
buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw) buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
{ {
if (Py_Py3kWarningFlag &&
PyErr_WarnEx(PyExc_DeprecationWarning,
"buffer will be removed in 3.x", 1) < 0)
return NULL;
PyObject *ob; PyObject *ob;
Py_ssize_t offset = 0; Py_ssize_t offset = 0;
Py_ssize_t size = Py_END_OF_BUFFER; Py_ssize_t size = Py_END_OF_BUFFER;