Skip to content

Commit d79216d

Browse files
[3.11] gh-107801: Improve the accuracy of io.IOBase.seek docs (#108268) (#108656)
(cherry picked from commit 8178a88) - Add param docstrings - Link to os.SEEK_* constants - Mention the return value in the initial paragraph Co-authored-by: Adam Turner <[email protected]>
1 parent 34f84f2 commit d79216d

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

Doc/library/io.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -403,20 +403,19 @@ 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-
be negative
416-
* :data:`!SEEK_END` or ``2`` -- end of the stream; *offset* is usually
417-
negative
418-
419-
Return the new absolute position.
415+
* :data:`os.SEEK_CUR` or ``1`` -- current stream position;
416+
*offset* may be negative
417+
* :data:`os.SEEK_END` or ``2`` -- end of the stream;
418+
*offset* is usually negative
420419

421420
.. versionadded:: 3.1
422421
The :data:`!SEEK_*` constants.
@@ -1061,14 +1060,17 @@ 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
.. method:: tell()
10651068

10661069
Return the stream position as an opaque number.
10671070
The return value of :meth:`!tell` can be given as input to :meth:`seek`,
10681071
to restore a previous stream position.
10691072

10701073

1071-
10721074
.. class:: StringIO(initial_value='', newline='\n')
10731075

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

Modules/_io/iobase.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,22 @@ iobase_unsupported(const char *message)
8282
/* Positioning */
8383

8484
PyDoc_STRVAR(iobase_seek_doc,
85-
"Change stream position.\n"
85+
"seek($self, offset, whence=os.SEEK_SET, /)\n"
86+
"--\n"
8687
"\n"
87-
"Change the stream position to the given byte offset. The offset is\n"
88-
"interpreted relative to the position indicated by whence. Values\n"
89-
"for whence are:\n"
88+
"Change the stream position to the given byte offset.\n"
9089
"\n"
91-
"* 0 -- start of stream (the default); offset should be zero or positive\n"
92-
"* 1 -- current stream position; offset may be negative\n"
93-
"* 2 -- end of stream; offset is usually negative\n"
90+
" offset\n"
91+
" The stream position, relative to \'whence\'.\n"
92+
" whence\n"
93+
" The relative position to seek from.\n"
94+
"\n"
95+
"The offset is interpreted relative to the position indicated by whence.\n"
96+
"Values for whence are:\n"
97+
"\n"
98+
"* os.SEEK_SET or 0 -- start of stream (the default); offset should be zero or positive\n"
99+
"* os.SEEK_CUR or 1 -- current stream position; offset may be negative\n"
100+
"* os.SEEK_END or 2 -- end of stream; offset is usually negative\n"
94101
"\n"
95102
"Return the new absolute position.");
96103

0 commit comments

Comments
 (0)