8000 gh-107801: Improve the accuracy of io.TextIOWrapper.seek docs by erlend-aasland · Pull Request #107933 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-107801: Improve the accuracy of io.TextIOWrapper.seek docs #107933

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

Merged
merged 6 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address first batch of reviews
  • Loading branch information
erlend-aasland committed Aug 14, 2023
commit fb86f3b46a446d30a5e774f64d665ee35f88a880
9 changes: 5 additions & 4 deletions Doc/library/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1045,18 +1045,19 @@ Text I/O

.. method:: seek(cookie, whence, /)

Set the stream position and return the current position.
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(n, SEEK_SET)``: Restore a previous position;
'n' is a number returned by :meth:`!tell`.
* ``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 undefined behaviour.
Any other argument combinations are invalid,
and may raise exceptions.

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

Expand Down
11 changes: 6 additions & 5 deletions Modules/_io/clinic/textio.c.h

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

11 changes: 6 additions & 5 deletions Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2433,23 +2433,24 @@ _io.TextIOWrapper.seek
The relative position to seek from.
/

Set the stream position and return the current position.
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(n, SEEK_SET): Restore a previous position;
'n' is a number returned by tell().
- 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 undefined behaviour.
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=10ce5c609984638a]*/
/*[clinic end generated code: output=0a15679764e2d04d input=0f68adcb02cf2823]*/
{
PyObject *posobj;
cookie_type cookie;
Expand Down
0