[Python-checkins] r63440 - in python/trunk: Lib/test/test_py3kwarn.py Misc/NEWS Objects/fileobject.c

georg.brandl python-checkins at python.org
Sun May 18 00:11:55 CEST 2008


Author: georg.brandl
Date: Sun May 18 00:11:54 2008
New Revision: 63440

Log:
#2353: raise Py3k warning in file.xreadlines().


Modified:
   python/trunk/Lib/test/test_py3kwarn.py
   python/trunk/Misc/NEWS
   python/trunk/Objects/fileobject.c

Modified: python/trunk/Lib/test/test_py3kwarn.py
==============================================================================
--- python/trunk/Lib/test/test_py3kwarn.py	(original)
+++ python/trunk/Lib/test/test_py3kwarn.py	Sun May 18 00:11:54 2008
@@ -123,6 +123,13 @@
         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):
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun May 18 00:11:54 2008
@@ -12,6 +12,8 @@
 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

Modified: python/trunk/Objects/fileobject.c
==============================================================================
--- python/trunk/Objects/fileobject.c	(original)
+++ python/trunk/Objects/fileobject.c	Sun May 18 00:11:54 2008
@@ -1736,6 +1736,15 @@
 }
 
 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)
 {
 	PyObject *ret = PyObject_CallMethod(f, "close", NULL);
@@ -1850,9 +1859,9 @@
 #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},


More information about the Python-checkins mailing list