]> granicus.if.org Git - python/commitdiff
#2355: py3k warning for buffer().
authorGeorg Brandl <georg@python.org>
Tue, 25 Mar 2008 07:56:27 +0000 (07:56 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 25 Mar 2008 07:56:27 +0000 (07:56 +0000)
Lib/test/test_py3kwarn.py
Misc/NEWS
Objects/bufferobject.c

index 07bcdf97d26e3cec18baf452a30cbcc61ce05e1e..41ad25bdf7461a299cf7010e6770344ad7e79b97 100644 (file)
@@ -118,6 +118,11 @@ class TestPy3KWarnings(unittest.TestCase):
             with catch_warning() as w:
                 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():
     run_unittest(TestPy3KWarnings)
index 3c42bce71dbac8f710a6a3329d6e752f12501261..881cc83a51b0b9206b9536754d7333cb1b0035b4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -11,7 +11,9 @@ What's New in Python 2.6 alpha 2?
 
 Core and builtins
 -----------------
+
+- Issue #2355: add Py3k warning for buffer().
+
 - Issue #1477: With narrow Unicode builds, the unicode escape sequence
   \Uxxxxxxxx did not accept values outside the Basic Multilingual Plane.  This
   affected raw unicode literals and the 'raw-unicode-escape' codec.  Now
index e01938c2e93c257152e823d328c2b1314dba9b32..0a818d634c15dfc2e29554894ae9eeb37c08ec49 100644 (file)
@@ -229,6 +229,11 @@ PyBuffer_New(Py_ssize_t size)
 static PyObject *
 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;
        Py_ssize_t offset = 0;
        Py_ssize_t size = Py_END_OF_BUFFER;