summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorngie-eign <1574099+ngie-eign@users.noreply.github.com>2019-03-03 07:28:26 (GMT)
committerInada Naoki <songofacandy@gmail.com>2019-03-03 07:28:26 (GMT)
commit848037c1476ddf86dd2798fca35527a63c764a8a (patch)
tree3db7ffcabbc9549e0db1669d4d0f37a9c19dd847 /Modules/_io
parent8589f14bbe55fb1ff5c765af5281100c38f0df63 (diff)
downloadcpython-848037c1476ddf86dd2798fca35527a63c764a8a.zip
cpython-848037c1476ddf86dd2798fca35527a63c764a8a.tar.gz
cpython-848037c1476ddf86dd2798fca35527a63c764a8a.tar.bz2
Use names SEEK_SET, etc instead of magic number (GH-12057)
The previous code hardcoded `SEEK_SET`, etc. While it's very unlikely that these values will change, it's best to use the definitions to avoid there being mismatches in behavior with the code in the future. Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/textio.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 14f9488..0f0092f 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -2344,7 +2344,8 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
goto fail;
}
- if (whence == 1) {
+ switch (whence) {
+ case SEEK_CUR:
/* seek relative to current position */
cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ);
if (cmp < 0)
@@ -2362,8 +2363,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
cookieObj = _PyObject_CallMethodId((PyObject *)self, &PyId_tell, NULL);
if (cookieObj == NULL)
goto fail;
- }
- else if (whence == 2) {
+ case SEEK_END:
/* seek relative to end of file */
cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ);
if (cmp < 0)
@@ -2401,10 +2401,12 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
}
}
return res;
- }
- else if (whence != 0) {
+ case SEEK_SET:
+ break;
+ default:
PyErr_Format(PyExc_ValueError,
- "invalid whence (%d, should be 0, 1 or 2)", whence);
+ "invalid whence (%d, should be %d, %d or %d)", whence,
+ SEEK_SET, SEEK_CUR, SEEK_END);
goto fail;
}