- Issue #6939: Fix file I/O objects in the `io` module to keep the original
file position when calling `truncate()`. It would previously change the
file position to the given argument, which goes against the tradition of
ftruncate() and other truncation APIs. Patch by Pascal Chambon.
diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c
index a5bfd79..505bde0 100644
--- a/Modules/_io/stringio.c
+++ b/Modules/_io/stringio.c
@@ -350,7 +350,7 @@
"Truncate size to pos.\n"
"\n"
"The pos argument defaults to the current file position, as\n"
- "returned by tell(). Imply an absolute seek to pos.\n"
+ "returned by tell(). The current file position is unchanged.\n"
"Returns the new absolute position.\n");
static PyObject *
@@ -390,7 +390,6 @@
return NULL;
self->string_size = size;
}
- self->pos = size;
return PyLong_FromSsize_t(size);
}