From 8ee524343445f7ac1c60df812deff17a92757c06 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 6 Aug 2002 17:14:04 +0000 Subject: [PATCH] Mark xreadlines deprecated. Don't use f.xreadlines() in test_iter.py. --- Lib/test/test_iter.py | 4 ++-- Lib/test/test_xreadline.py | 3 +++ Modules/xreadlinesmodule.c | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py index 509ec01b279..62a8d02f8d1 100644 --- a/Lib/test/test_iter.py +++ b/Lib/test/test_iter.py @@ -269,7 +269,7 @@ def test_builtin_list(self): try: self.assertEqual(list(f), ["0\n", "1\n", "2\n", "3\n", "4\n"]) f.seek(0, 0) - self.assertEqual(list(f.xreadlines()), + self.assertEqual(list(f), ["0\n", "1\n", "2\n", "3\n", "4\n"]) finally: f.close() @@ -302,7 +302,7 @@ def test_builtin_tuple(self): try: self.assertEqual(tuple(f), ("0\n", "1\n", "2\n", "3\n", "4\n")) f.seek(0, 0) - self.assertEqual(tuple(f.xreadlines()), + self.assertEqual(tuple(f), ("0\n", "1\n", "2\n", "3\n", "4\n")) finally: f.close() diff --git a/Lib/test/test_xreadline.py b/Lib/test/test_xreadline.py index db9eb6bd43f..0ba4adcb281 100644 --- a/Lib/test/test_xreadline.py +++ b/Lib/test/test_xreadline.py @@ -1,5 +1,8 @@ from test.test_support import verbose +import warnings +warnings.filterwarnings('ignore', "xreadlines", DeprecationWarning) + class XReader: def __init__(self): self.count = 5 diff --git a/Modules/xreadlinesmodule.c b/Modules/xreadlinesmodule.c index 3009768192d..bf3c091df05 100644 --- a/Modules/xreadlinesmodule.c +++ b/Modules/xreadlinesmodule.c @@ -173,4 +173,6 @@ initxreadlines(void) { XReadlinesObject_Type.ob_type = &PyType_Type; Py_InitModule("xreadlines", xreadlines_functions); + PyErr_Warn(PyExc_DeprecationWarning, + "xreadlines is deprecated; use 'for line in file'."); }