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

Skip to content

Commit dd4442c

Browse files
gh-107801: Improve the accuracy of os.lseek docs (#107935)
- name the last parameter *whence*, like it is for seek() methods on file objects - add param docstrings - structure the valid *whence* params Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent 6db39b1 commit dd4442c

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
@@ -10424,19 +10424,24 @@ os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length)
1042410424
os.lseek -> Py_off_t
1042510425
1042610426
fd: int
10427+
An open file descriptor, as returned by os.open().
1042710428
position: Py_off_t
10428-
how: int
10429+
Position, interpreted relative to 'whence'.
10430+
whence as how: int
10431+
The relative position to seek from. Valid values are:
10432+
- SEEK_SET: seek from the start of the file.
10433+
- SEEK_CUR: seek from the current file position.
10434+
- SEEK_END: seek from the end of the file.
1042910435
/
1043010436
1043110437
Set the position of a file descriptor. Return the new position.
1043210438
10433-
Return the new cursor position in number of bytes
10434-
relative to the beginning of the file.
10439+
The return value is the number of bytes relative to the beginning of the file.
1043510440
[clinic start generated code]*/
1043610441

1043710442
static Py_off_t
1043810443
os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how)
10439-
/*[clinic end generated code: output=971e1efb6b30bd2f input=902654ad3f96a6d3]*/
10444+
/*[clinic end generated code: output=971e1efb6b30bd2f input=f096e754c5367504]*/
1044010445
{
1044110446
Py_off_t result;
1044210447

0 commit comments

Comments
 (0)
0