From 2af0eb87e760176d69edd279952ac5a1b6087085 Mon Sep 17 00:00:00 2001 From: Jonathon Reinhart Date: Thu, 23 Mar 2023 10:11:23 -0400 Subject: [PATCH 1/2] Fix an incorrect comment This comment appears to have been mistakenly copied from what is now called iobase_check_closed() in commit 4d9aec022063. --- Modules/_io/iobase.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 682ed000eb1fd9..504664a191b33a 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -130,8 +130,7 @@ iobase_is_closed(PyObject *self) { PyObject *res; int ret; - /* This gets the derived attribute, which is *not* __IOBase_closed - in most cases! */ + /* This gets the IOBase internal attribute. */ ret = _PyObject_LookupAttr(self, &_Py_ID(__IOBase_closed), &res); Py_XDECREF(res); return ret; From 42792e11efbe680d20b93a78704cac46d58ea14a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 16 Jan 2024 17:12:12 +0200 Subject: [PATCH 2/2] Move to the related comment. --- Modules/_io/iobase.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 2a06e286d80ee3..184e0b7d1aa7f1 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -66,12 +66,19 @@ PyDoc_STRVAR(iobase_doc, "with open('spam.txt', 'r') as fp:\n" " fp.write('Spam and eggs!')\n"); -/* Use this macro whenever you want to check the internal `closed` status + +/* Internal methods */ + +/* Use this function whenever you want to check the internal `closed` status of the IOBase object rather than the virtual `closed` attribute as returned by whatever subclass. */ +static int +iobase_is_closed(PyObject *self) +{ + return PyObject_HasAttrWithError(self, &_Py_ID(__IOBase_closed)); +} -/* Internal methods */ static PyObject * iobase_unsupported(_PyIO_State *state, const char *message) { @@ -145,13 +152,6 @@ _io__IOBase_truncate_impl(PyObject *self, PyTypeObject *cls, return iobase_unsupported(state, "truncate"); } -static int -iobase_is_closed(PyObject *self) -{ - /* This gets the IOBase internal attribute. */ - return PyObject_HasAttrWithError(self, &_Py_ID(__IOBase_closed)); -} - /* Flush and close methods */ /*[clinic input]