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

[3.11] gh-107801: Improve the accuracy of io.TextIOWrapper.seek docs (#107933) #108264

Merged
merged 1 commit into from
Aug 22, 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
16 changes: 16 additions & 0 deletions Doc/library/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,22 @@ Text I/O
.. versionchanged:: 3.11
The method supports ``encoding="locale"`` option.

.. method:: seek(cookie, whence=os.SEEK_SET, /)

Set the stream position.
Return the new stream position as an :class:`int`.

Four operations are supported,
given by the following argument combinations:

* ``seek(0, SEEK_SET)``: Rewind to the start of the stream.
* ``seek(cookie, SEEK_SET)``: Restore a previous position;
*cookie* **must be** a number returned by :meth:`!tell`.
* ``seek(0, SEEK_END)``: Fast-forward to the end of the stream.
* ``seek(0, SEEK_CUR)``: Leave the current stream position unchanged.

Any other argument combinations are invalid,
and may raise exceptions.

.. class:: StringIO(initial_value='', newline='\n')

Expand Down
24 changes: 21 additions & 3 deletions Modules/_io/clinic/textio.c.h

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

20 changes: 18 additions & 2 deletions Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2415,13 +2415,29 @@ _textiowrapper_encoder_setstate(textio *self, cookie_type *cookie)
/*[clinic input]
_io.TextIOWrapper.seek
cookie as cookieObj: object
whence: int = 0
Zero or an opaque number returned by tell().
whence: int(c_default='0') = os.SEEK_SET
The relative position to seek from.
/

Set the stream position, and return the new stream position.

Four operations are supported, given by the following argument
combinations:

- seek(0, SEEK_SET): Rewind to the start of the stream.
- seek(cookie, SEEK_SET): Restore a previous position;
'cookie' must be a number returned by tell().
- seek(0, SEEK_END): Fast-forward to the end of the stream.
- seek(0, SEEK_CUR): Leave the current stream position unchanged.

Any other argument combinations are invalid,
and may raise exceptions.
[clinic start generated code]*/

static PyObject *
_io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
/*[clinic end generated code: output=0a15679764e2d04d input=0458abeb3d7842be]*/
/*[clinic end generated code: output=0a15679764e2d04d input=0f68adcb02cf2823]*/
{
PyObject *posobj;
cookie_type cookie;
Expand Down
Loading