8000 [3.12] gh-107801: Improve the accuracy of os.lseek docs (#107935) (#1… · python/cpython@41634ed · GitHub
[go: up one dir, main page]

Skip to content

Commit 41634ed

Browse files
[3.12] gh-107801: Improve the accuracy of os.lseek docs (#107935) (#108136)
- 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 <9087854+AA-Turner@users.noreply.github.com>
1 parent 2807430 commit 41634ed

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
@@ -1163,17 +1163,22 @@ as internal buffering of data.
11631163
.. versionadded:: 3.11
11641164

11651165

1166-
.. function:: lseek(fd, pos, how, /)
1166+
.. function:: lseek(fd, pos, whence, /)
11671167

11681168
Set the current position of file descriptor *fd* to position *pos*, modified
1169-
by *how*: :const:`SEEK_SET` or ``0`` to set the position relative to the
1170-
beginning of the file; :const:`SEEK_CUR` or ``1`` to set it relative to the
1171-
current position; :const:`SEEK_END` or ``2`` to set it relative to the end of
1172-
the file. Return the new cursor position in bytes, starting from the beginning.
1169+
by *whence*, and return the new position in bytes relative to
1170+
the start of the file.
1171+
Valid values for *whence* are:
1172+
1173+
* :const:`SEEK_SET` or ``0`` -- set *pos* relative to the beginning of the file
1174+
* :const:`SEEK_CUR` or ``1`` -- set *pos* relative to the current file position
1175+
* :const:`SEEK_END` or ``2`` -- set *pos* relative to the end of the file
1176+
* :const:`SEEK_HOLE` -- set *pos* to the next data location, relative to *pos*
1177+
* :const:`SEEK_DATA` -- set *pos* to the next data hole, relative to *pos*
11731178

11741179
.. versionchanged:: 3.3
11751180

1176-
Add support for :const:`SEEK_HOLE` and :const:`SEEK_DATA`.
1181+
Add support for :const:`!SEEK_HOLE` and :const:`!SEEK_DATA`.
11771182

11781183

11791184
.. 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
@@ -10421,19 +10421,24 @@ os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length)
1042110421
os.lseek -> Py_off_t
1042210422
1042310423
fd: int
10424+
An open file descriptor, as returned by os.open().
1042410425
position: Py_off_t
10425-
how: int
10426+
Position, interpreted relative to 'whence'.
10427+
whence as how: int
10428+
The relative position to seek from. Valid values are:
10429+
- SEEK_SET: seek from the start of the file.
10430+
- SEEK_CUR: seek from the current file position.
10431+
- SEEK_END: seek from the end of the file.
1042610432
/
1042710433
1042810434
Set the position of a file descriptor. Return the new position.
1042910435
10430-
Return the new cursor position in number of bytes
10431-
relative to the beginning of the file.
10436+
The return value is the number of bytes relative to the beginning of the file.
1043210437
[clinic start generated code]*/
1043310438

1043410439
static Py_off_t
1043510440
os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how)
10436-
/*[clinic end generated code: output=971e1efb6b30bd2f input=902654ad3f96a6d3]*/
10441+
/*[clinic end generated code: output=971e1efb6b30bd2f input=f096e754c5367504]*/
1043710442
{
1043810443
Py_off_t result;
1043910444

0 commit comments

Comments
 (0)
0