Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 649b759

Browse files
committed
SF Patch #494863, file.xreadlines() should raise ValueError if file is closed
This makes xreadlines behave like all other file methods (other than close() which just returns).
1 parent a6e9758 commit 649b759

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Type/class unification and new-style classes
66

77
Core and builtins
88

9+
- file.xreadlines() now raises a ValueError if the file is closed:
10+
Previously, an xreadlines object was returned which would raise
11+
a ValueError when the xreadlines.next() method was called.
12+
913
Extension modules
1014

1115
Library

Objects/fileobject.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,8 @@ file_xreadlines(PyFileObject *f)
10251025
{
10261026
static PyObject* xreadlines_function = NULL;
10271027

1028+
if (f->f_fp == NULL)
1029+
return err_closed();
10281030
if (!xreadlines_function) {
10291031
PyObject *xreadlines_module =
10301032
PyImport_ImportModule("xreadlines");

0 commit comments

Comments
 (0)