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

gh-101819: Adapt _io.IOBase.seek and _io.IOBase.truncate to Argument Clinic #104384

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 101 additions & 1 deletion Modules/_io/clinic/iobase.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 34 additions & 21 deletions Modules/_io/iobase.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,27 @@ iobase_unsupported(_PyIO_State *state, const char *message)

/* Positioning */

PyDoc_STRVAR(iobase_seek_doc,
"Change stream position.\n"
"\n"
"Change the stream position to the given byte offset. The offset is\n"
"interpreted relative to the position indicated by whence. Values\n"
"for whence are:\n"
"\n"
"* 0 -- start of stream (the default); offset should be zero or positive\n"
"* 1 -- current stream position; offset may be negative\n"
"* 2 -- end of stream; offset is usually negative\n"
"\n"
"Return the new absolute position.");
/*[clinic input]
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
_io._IOBase.seek
cls: defining_class
/
*args: object

Change the stream position to the given byte offset.

The offset is interpreted relative to the position indicated by whence.
Values for whence are:

* 0 -- start of stream (the default); offset should be zero or positive
* 1 -- current stream position; offset may be negative
* 2 -- end of stream; offset is usually negative

Return the new absolute position.
[clinic start generated code]*/

static PyObject *
iobase_seek(PyObject *self, PyObject *args)
_io__IOBase_seek_impl(PyObject *self, PyTypeObject *cls, PyObject *args)
/*[clinic end generated code: output=1dd694ac9de260fa input=ebb5476eb22fc5d4]*/
{
_PyIO_State *state = IO_STATE();
return iobase_unsupported(state, "seek");
Expand All @@ -112,14 +118,21 @@ _io__IOBase_tell_impl(PyObject *self)
return _PyObject_CallMethod(self, &_Py_ID(seek), "ii", 0, 1);
}

PyDoc_STRVAR(iobase_truncate_doc,
"Truncate file to size bytes.\n"
"\n"
"File pointer is left unchanged. Size defaults to the current IO\n"
"position as reported by tell(). Returns the new size.");
/*[clinic input]
_io._IOBase.truncate
cls: defining_class
/
*args: object

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position
as reported by tell(). Return the new size.
[clinic start generated code]*/

static PyObject *
iobase_truncate(PyObject *self, PyObject *args)
_io__IOBase_truncate_impl(PyObject *self, PyTypeObject *cls, PyObject *args)
/*[clinic end generated code: output=b7eed4649cbe22c1 input=ad90582a1d8b5cc9]*/
{
_PyIO_State *state = IO_STATE();
return iobase_unsupported(state, "truncate");
Expand Down Expand Up @@ -809,9 +822,9 @@ _io__IOBase_writelines(PyObject *self, PyObject *lines)
#include "clinic/iobase.c.h"

static PyMethodDef iobase_methods[] = {
{"seek", iobase_seek, METH_VARARGS, iobase_seek_doc},
_IO__IOBASE_SEEK_METHODDEF
_IO__IOBASE_TELL_METHODDEF
{"truncate", iobase_truncate, METH_VARARGS, iobase_truncate_doc},
_IO__IOBASE_TRUNCATE_METHODDEF
_IO__IOBASE_FLUSH_METHODDEF
_IO__IOBASE_CLOSE_METHODDEF

Expand Down