Skip to content

Commit

Permalink
Remove unnecessary check in _IOBase._check*() methods
Browse files Browse the repository at this point in the history
These methods are METH_NOARGS, in all cases the second parameter will be NULL.
  • Loading branch information
Ma Lin committed Jan 5, 2022
1 parent a09062c commit f232cfa
Showing 1 changed file with 20 additions and 29 deletions.
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

0 comments on commit f232cfa

Please sign in to comment.