Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-46255: Remove unnecessary check in _IOBase._check*() methods #30397

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 20 additions & 29 deletions Modules/_io/iobase.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,11 @@ iobase_check_closed(PyObject *self)
}

PyObject *
_PyIOBase_check_closed(PyObject *self, PyObject *args)
_PyIOBase_check_closed(PyObject *self, PyObject *Py_UNUSED(ignored))
{
if (iobase_check_closed(self)) {
return NULL;
}
if (args == Py_True) {
return Py_None;
}
Py_RETURN_NONE;
}

Expand Down Expand Up @@ -381,20 +378,18 @@ _io__IOBase_seekable_impl(PyObject *self)
}

PyObject *
_PyIOBase_check_seekable(PyObject *self, PyObject *args)
_PyIOBase_check_seekable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *res = PyObject_CallMethodNoArgs(self, _PyIO_str_seekable);
if (res == NULL)
PyObject *res = PyObject_CallMethodNoArgs(self, _PyIO_str_seekable);
if (res == NULL) {
return NULL;
if (res != Py_True) {
Py_CLEAR(res);
} else if (res == Py_True) {
return res;
} else {
Py_DECREF(res);
iobase_unsupported("File or stream is not seekable.");
return NULL;
}
if (args == Py_True) {
Py_DECREF(res);
}
return res;
}

/*[clinic input]
Expand All @@ -414,20 +409,18 @@ _io__IOBase_readable_impl(PyObject *self)

/* May be called with any object */
PyObject *
_PyIOBase_check_readable(PyObject *self, PyObject *args)
_PyIOBase_check_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *res = PyObject_CallMethodNoArgs(self, _PyIO_str_readable);
if (res == NULL)
if (res == NULL) {
return NULL;
if (res != Py_True) {
Py_CLEAR(res);
} else if (res == Py_True) {
return res;
} else {
Py_DECREF(res);
iobase_unsupported("File or stream is not readable.");
return NULL;
}
if (args == Py_True) {
Py_DECREF(res);
}
return res;
}

/*[clinic input]
Expand All @@ -447,20 +440,18 @@ _io__IOBase_writable_impl(PyObject *self)

/* May be called with any object */
PyObject *
_PyIOBase_check_writable(PyObject *self, PyObject *args)
_PyIOBase_check_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *res = PyObject_CallMethodNoArgs(self, _PyIO_str_writable);
if (res == NULL)
if (res == NULL) {
return NULL;
if (res != Py_True) {
Py_CLEAR(res);
} else if (res == Py_True) {
return res;
} else {
Py_DECREF(res);
iobase_unsupported("File or stream is not writable.");
return NULL;
}
if (args == Py_True) {
Py_DECREF(res);
}
return res;
}

/* Context manager */
Expand Down