Skip to content

Commit 44c6575

Browse files
pythongh-107801: Improve the accuracy of io.IOBase.seek docs
- Add param docstrings - Link to os.SEEK_* constants - Mention the return value in the initial paragraph
1 parent 8661751 commit 44c6575

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

Doc/library/io.rst

+12-9
Original file line numberDiff line numberDiff line change
@@ -403,21 +403,20 @@ I/O Base Classes
403403
Note that it's already possible to iterate on file objects using ``for
404404
line in file: ...`` without calling :meth:`!file.readlines`.
405405

406-
.. method:: seek(offset, whence=SEEK_SET, /)
406+
.. method:: seek(offset, whence=os.SEEK_SET, /)
407407

408-
Change the stream position to the given byte *offset*. *offset* is
409-
interpreted relative to the position indicated by *whence*. The default
410-
value for *whence* is :data:`!SEEK_SET`. Values for *whence* are:
408+
Change the stream position to the given byte *offset*,
409+
interpreted relative to the position indicated by *whence*,
410+
and return the new absolute position.
411+
Values for *whence* are:
411412

412-
* :data:`!SEEK_SET` or ``0`` -- start of the stream (the default);
413+
* :data:`os.SEEK_SET` or ``0`` -- start of the stream (the default);
413414
*offset* should be zero or positive
414-
* :data:`!SEEK_CUR` or ``1`` -- current stream position; *offset* may
415+
* :data:`os.SEEK_CUR` or ``1`` -- current stream position; *offset* may
415416
be negative
416-
* :data:`!SEEK_END` or ``2`` -- end of the stream; *offset* is usually
417+
* :data:`os.SEEK_END` or ``2`` -- end of the stream; *offset* is usually
417418
negative
418419

419-
Return the new absolute position.
420-
421420
.. versionadded:: 3.1
422421
The :data:`!SEEK_*` constants.
423422

@@ -1061,6 +1060,10 @@ Text I/O
10611060
Any other argument combinations are invalid,
10621061
and may raise exceptions.
10631062

1063+
.. seealso::
1064+
1065+
:data:`os.SEEK_SET`, :data:`os.SEEK_CUR`, and :data:`os.SEEK_END`.
1066+
10641067
.. class:: StringIO(initial_value='', newline='\n')
10651068

10661069
A text stream using an in-memory text buffer. It inherits

Modules/_io/clinic/iobase.c.h

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/iobase.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ iobase_unsupported(_PyIO_State *state, const char *message)
8383
_io._IOBase.seek
8484
cls: defining_class
8585
offset: int(unused=True)
86+
The stream position, relative to 'whence'.
8687
whence: int(unused=True, c_default='0') = os.SEEK_SET
88+
The relative position to seek from.
8789
/
8890
8991
Change the stream position to the given byte offset.
@@ -101,7 +103,7 @@ Return the new absolute position.
101103
static PyObject *
102104
_io__IOBase_seek_impl(PyObject *self, PyTypeObject *cls,
103105
int Py_UNUSED(offset), int Py_UNUSED(whence))
104-
/*[clinic end generated code: output=8bd74ea6538ded53 input=8d4e6adcd08292f2]*/
106+
/*[clinic end generated code: output=8bd74ea6538ded53 input=74211232b363363e]*/
105107
{
106108
_PyIO_State *state = get_io_state_by_cls(cls);
107109
return iobase_unsupported(state, "seek");

0 commit comments

Comments
 (0)