Skip to content

Commit e0ca342

Browse files
[3.11] gh-107801: Improve the accuracy of os.lseek docs (#107935) (#108137)
- name the last parameter *whence*, like it is for seek() methods on file objects - add param docstrings - structure the valid *whence* params (cherry picked from commit dd4442c) Co-authored-by: Adam Turner <[email protected]>
1 parent 92a5784 commit e0ca342

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

Doc/library/os.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,17 +1053,22 @@ as internal buffering of data.
10531053
.. versionadded:: 3.11
10541054

10551055

1056-
.. function:: lseek(fd, pos, how, /)
1056+
.. function:: lseek(fd, pos, whence, /)
10571057

10581058
Set the current position of file descriptor *fd* to position *pos*, modified
1059-
by *how*: :const:`SEEK_SET` or ``0`` to set the position relative to the
1060-
beginning of the file; :const:`SEEK_CUR` or ``1`` to set it relative to the
1061-
current position; :const:`SEEK_END` or ``2`` to set it relative to the end of
1062-
the file. Return the new cursor position in bytes, starting from the beginning.
1059+
by *whence*, and return the new position in bytes relative to
1060+
the start of the file.
1061+
Valid values for *whence* are:
1062+
1063+
* :const:`SEEK_SET` or ``0`` -- set *pos* relative to the beginning of the file
1064+
* :const:`SEEK_CUR` or ``1`` -- set *pos* relative to the current file position
1065+
* :const:`SEEK_END` or ``2`` -- set *pos* relative to the end of the file
1066+
* :const:`SEEK_HOLE` -- set *pos* to the next data location, relative to *pos*
1067+
* :const:`SEEK_DATA` -- set *pos* to the next data hole, relative to *pos*
10631068

10641069
.. versionchanged:: 3.3
10651070

1066-
Add support for :const:`SEEK_HOLE` and :const:`SEEK_DATA`.
1071+
Add support for :const:`!SEEK_HOLE` and :const:`!SEEK_DATA`.
10671072

10681073

10691074
.. data:: SEEK_SET

Modules/clinic/posixmodule.c.h

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/posixmodule.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9521,19 +9521,24 @@ os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length)
95219521
os.lseek -> Py_off_t
95229522
95239523
fd: int
9524+
An open file descriptor, as returned by os.open().
95249525
position: Py_off_t
9525-
how: int
9526+
Position, interpreted relative to 'whence'.
9527+
whence as how: int
9528+
The relative position to seek from. Valid values are:
9529+
- SEEK_SET: seek from the start of the file.
9530+
- SEEK_CUR: seek from the current file position.
9531+
- SEEK_END: seek from the end of the file.
95269532
/
95279533
95289534
Set the position of a file descriptor. Return the new position.
95299535
9530-
Return the new cursor position in number of bytes
9531-
relative to the beginning of the file.
9536+
The return value is the number of bytes relative to the beginning of the file.
95329537
[clinic start generated code]*/
95339538

95349539
static Py_off_t
95359540
os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how)
9536-
/*[clinic end generated code: output=971e1efb6b30bd2f input=902654ad3f96a6d3]*/
9541+
/*[clinic end generated code: output=971e1efb6b30bd2f input=f096e754c5367504]*/
95379542
{
95389543
Py_off_t result;
95399544

0 commit comments

Comments
 (0)