]> granicus.if.org Git - python/commitdiff
#2353: raise Py3k warning in file.xreadlines().
authorGeorg Brandl <georg@python.org>
Sat, 17 May 2008 22:11:54 +0000 (22:11 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 17 May 2008 22:11:54 +0000 (22:11 +0000)
Lib/test/test_py3kwarn.py
Misc/NEWS
Objects/fileobject.c

index 1a65323e4c327e03f30a80081d090f7a40e2fb02..d64d66aff2be75904ed416ffe6a0c9067435b18f 100644 (file)
@@ -123,6 +123,13 @@ class TestPy3KWarnings(unittest.TestCase):
         with catch_warning() as w:
             self.assertWarning(buffer('a'), w, expected)
 
+    def test_file_xreadlines(self):
+        expected = ("f.xreadlines() not supported in 3.x, "
+                    "try 'for line in f' instead")
+        with file(__file__) as f:
+            with catch_warning() as w:
+                self.assertWarning(f.xreadlines(), w, expected)
+
 
 class TestStdlibRemovals(unittest.TestCase):
 
index 8ee4d4d9dcd81c64ac962c195b6c58eb894d96d4..039fd7dbdcdeb73044bb1527e6ec91c6b921a904 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.6 beta 1?
 Core and Builtins
 -----------------
 
+- Issue #2353: file.xreadlines() now emits a Py3k warning.
+
 - Issue #2863: generators now have a ``gen.__name__`` attribute that
   equals ``gen.gi_code.co_name``, like ``func.__name___`` that equals
   ``func.func_code.co_name``.  The repr() of a generator now also
index 40ea9441cbde6e884ea965650fe34202ac7daa7e..4f8c46b0de3f6957a8cc3a178c69c38a80c78f6f 100644 (file)
@@ -1735,6 +1735,15 @@ file_self(PyFileObject *f)
        return (PyObject *)f;
 }
 
+static PyObject *
+file_xreadlines(PyFileObject *f)
+{
+       if (PyErr_WarnPy3k("f.xreadlines() not supported in 3.x, "
+                          "try 'for line in f' instead", 1) < 0)
+              return NULL;
+       return file_self(f);
+}
+
 static PyObject *
 file_exit(PyObject *f, PyObject *args)
 {
@@ -1850,9 +1859,9 @@ static PyMethodDef file_methods[] = {
 #endif
        {"tell",      (PyCFunction)file_tell,     METH_NOARGS,  tell_doc},
        {"readinto",  (PyCFunction)file_readinto, METH_VARARGS, readinto_doc},
-       {"readlines", (PyCFunction)file_readlines,METH_VARARGS, readlines_doc},
-       {"xreadlines",(PyCFunction)file_self,     METH_NOARGS, xreadlines_doc},
-       {"writelines",(PyCFunction)file_writelines, METH_O,    writelines_doc},
+       {"readlines", (PyCFunction)file_readlines, METH_VARARGS, readlines_doc},
+       {"xreadlines",(PyCFunction)file_xreadlines, METH_NOARGS, xreadlines_doc},
+       {"writelines",(PyCFunction)file_writelines, METH_O,     writelines_doc},
        {"flush",     (PyCFunction)file_flush,    METH_NOARGS,  flush_doc},
        {"close",     (PyCFunction)file_close,    METH_NOARGS,  close_doc},
        {"isatty",    (PyCFunction)file_isatty,   METH_NOARGS,  isatty_doc},