Skip to content

Commit d7b146e

Browse files
committed
Adjust closed_get_impl
1 parent 452168c commit d7b146e

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

Modules/_io/textio.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,11 +3325,16 @@ static PyObject *
33253325
_io_TextIOWrapper_closed_get_impl(textio *self)
33263326
/*[clinic end generated code: output=b49b68f443a85e3c input=7dfcf43f63c7003d]*/
33273327
{
3328-
/* During destruction self->ok is 0 but self->buffer is non-NULL and this
3329-
needs to error in that case which the safe buffer wrapper does not.
3328+
/* If partially constructed or deconstructed return that the underlying
3329+
buffer is closed.
3330+
3331+
The code managing the transition is responsible for closing. The closed
3332+
attribute is often called in re-initalization, as part of repr in error
3333+
cases, and when the I/O stack is garbage collected. */
3334+
if (self->ok <= 0) {
3335+
Py_RETURN_TRUE;
3336+
}
33303337

3331-
Match original behavior by calling CHECK_ATTACHED explicitly. */
3332-
CHECK_ATTACHED(self);
33333338
return buffer_getattr(self, &_Py_ID(closed));
33343339
}
33353340

0 commit comments

Comments
 (0)