Skip to content

Commit cb4f7c4

Browse files
[3.14] pythongh-140615: Update docstrings in the fcntl module (pythonGH-140619)
* Refer to bytes objects or bytes-like objects instead of strings. * Remove backticks -- they do not have effect on formatting. * Re-wrap lines to ensure the pydoc output fits in 80 coluimns. * Remove references to the 1024 bytes limit. (cherry picked from commit 6103770) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent de00dde commit cb4f7c4

File tree

2 files changed

+98
-90
lines changed

2 files changed

+98
-90
lines changed

Modules/clinic/fcntlmodule.c.h

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

Modules/fcntlmodule.c

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,27 @@ fcntl.fcntl
4141
arg: object(c_default='NULL') = 0
4242
/
4343
44-
Perform the operation `cmd` on file descriptor fd.
45-
46-
The values used for `cmd` are operating system dependent, and are available
47-
as constants in the fcntl module, using the same names as used in
48-
the relevant C header files. The argument arg is optional, and
49-
defaults to 0; it may be an int or a string. If arg is given as a string,
50-
the return value of fcntl is a string of that length, containing the
51-
resulting value put in the arg buffer by the operating system. The length
52-
of the arg string is not allowed to exceed 1024 bytes. If the arg given
53-
is an integer or if none is specified, the result value is an integer
54-
corresponding to the return value of the fcntl call in the C code.
44+
Perform the operation cmd on file descriptor fd.
45+
46+
The values used for cmd are operating system dependent, and are
47+
available as constants in the fcntl module, using the same names as used
48+
in the relevant C header files. The argument arg is optional, and
49+
defaults to 0; it may be an integer, a bytes-like object or a string.
50+
If arg is given as a string, it will be encoded to binary using the
51+
UTF-8 encoding.
52+
53+
If the arg given is an integer or if none is specified, the result value
54+
is an integer corresponding to the return value of the fcntl() call in
55+
the C code.
56+
57+
If arg is given as a bytes-like object, the return value of fcntl() is a
58+
bytes object of that length, containing the resulting value put in the
59+
arg buffer by the operating system.
5560
[clinic start generated code]*/
5661

5762
static PyObject *
5863
fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
59-
/*[clinic end generated code: output=888fc93b51c295bd input=7955340198e5f334]*/
64+
/*[clinic end generated code: output=888fc93b51c295bd input=77340720f11665da]*/
6065
{
6166
int ret;
6267
int async_err = 0;
@@ -135,40 +140,39 @@ fcntl.ioctl
135140
mutate_flag as mutate_arg: bool = True
136141
/
137142
138-
Perform the operation `request` on file descriptor `fd`.
143+
Perform the operation request on file descriptor fd.
139144
140-
The values used for `request` are operating system dependent, and are available
141-
as constants in the fcntl or termios library modules, using the same names as
142-
used in the relevant C header files.
145+
The values used for request are operating system dependent, and are
146+
available as constants in the fcntl or termios library modules, using
147+
the same names as used in the relevant C header files.
143148
144-
The argument `arg` is optional, and defaults to 0; it may be an int or a
145-
buffer containing character data (most likely a string or an array).
149+
The argument arg is optional, and defaults to 0; it may be an integer, a
150+
bytes-like object or a string. If arg is given as a string, it will be
151+
encoded to binary using the UTF-8 encoding.
146152
147-
If the argument is a mutable buffer (such as an array) and if the
148-
mutate_flag argument (which is only allowed in this case) is true then the
149-
buffer is (in effect) passed to the operating system and changes made by
150-
the OS will be reflected in the contents of the buffer after the call has
151-
returned. The return value is the integer returned by the ioctl system
152-
call.
153+
If the arg given is an integer or if none is specified, the result value
154+
is an integer corresponding to the return value of the ioctl() call in
155+
the C code.
153156
154-
If the argument is a mutable buffer and the mutable_flag argument is false,
155-
the behavior is as if a string had been passed.
157+
If the argument is a mutable buffer (such as a bytearray) and the
158+
mutate_flag argument is true (default) then the buffer is (in effect)
159+
passed to the operating system and changes made by the OS will be
160+
reflected in the contents of the buffer after the call has returned.
161+
The return value is the integer returned by the ioctl() system call.
156162
157-
If the argument is an immutable buffer (most likely a string) then a copy
158-
of the buffer is passed to the operating system and the return value is a
159-
string of the same length containing whatever the operating system put in
160-
the buffer. The length of the arg buffer in this case is not allowed to
161-
exceed 1024 bytes.
163+
If the argument is a mutable buffer and the mutable_flag argument is
164+
false, the behavior is as if an immutable buffer had been passed.
162165
163-
If the arg given is an integer or if none is specified, the result value is
164-
an integer corresponding to the return value of the ioctl call in the C
165-
code.
166+
If the argument is an immutable buffer then a copy of the buffer is
167+
passed to the operating system and the return value is a bytes object of
168+
the same length containing whatever the operating system put in the
169+
buffer.
166170
[clinic start generated code]*/
167171

168172
static PyObject *
169173
fcntl_ioctl_impl(PyObject *module, int fd, unsigned long code, PyObject *arg,
170174
int mutate_arg)
171-
/*[clinic end generated code: output=f72baba2454d7a62 input=9c6cca5e2c339622]*/
175+
/*[clinic end generated code: output=f72baba2454d7a62 input=954fe75c208cc492]*/
172176
{
173177
/* We use the unsigned non-checked 'I' format for the 'code' parameter
174178
because the system expects it to be a 32bit bit field value
@@ -290,15 +294,15 @@ fcntl.flock
290294
operation as code: int
291295
/
292296
293-
Perform the lock operation `operation` on file descriptor `fd`.
297+
Perform the lock operation on file descriptor fd.
294298
295299
See the Unix manual page for flock(2) for details (On some systems, this
296300
function is emulated using fcntl()).
297301
[clinic start generated code]*/
298302

299303
static PyObject *
300304
fcntl_flock_impl(PyObject *module, int fd, int code)
301-
/*[clinic end generated code: output=84059e2b37d2fc64 input=0bfc00f795953452]*/
305+
/*[clinic end generated code: output=84059e2b37d2fc64 input=ade68943e8599f0a]*/
302306
{
303307
int ret;
304308
int async_err = 0;
@@ -361,22 +365,22 @@ fcntl.lockf
361365
362366
A wrapper around the fcntl() locking calls.
363367
364-
`fd` is the file descriptor of the file to lock or unlock, and operation is one
365-
of the following values:
368+
fd is the file descriptor of the file to lock or unlock, and operation
369+
is one of the following values:
366370
367371
LOCK_UN - unlock
368372
LOCK_SH - acquire a shared lock
369373
LOCK_EX - acquire an exclusive lock
370374
371375
When operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with
372-
LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and the
373-
lock cannot be acquired, an OSError will be raised and the exception will
374-
have an errno attribute set to EACCES or EAGAIN (depending on the operating
375-
system -- for portability, check for either value).
376+
LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and
377+
the lock cannot be acquired, an OSError will be raised and the exception
378+
will have an errno attribute set to EACCES or EAGAIN (depending on the
379+
operating system -- for portability, check for either value).
376380
377-
`len` is the number of bytes to lock, with the default meaning to lock to
378-
EOF. `start` is the byte offset, relative to `whence`, to that the lock
379-
starts. `whence` is as with fileobj.seek(), specifically:
381+
len is the number of bytes to lock, with the default meaning to lock to
382+
EOF. start is the byte offset, relative to whence, to that the lock
383+
starts. whence is as with fileobj.seek(), specifically:
380384
381385
0 - relative to the start of the file (SEEK_SET)
382386
1 - relative to the current buffer position (SEEK_CUR)
@@ -386,7 +390,7 @@ starts. `whence` is as with fileobj.seek(), specifically:
386390
static PyObject *
387391
fcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj,
388392
PyObject *startobj, int whence)
389-
/*[clinic end generated code: output=4985e7a172e7461a input=5480479fc63a04b8]*/
393+
/*[clinic end generated code: output=4985e7a172e7461a input=369bef4d7a1c5ff4]*/
390394
{
391395
int ret;
392396
int async_err = 0;

0 commit comments

Comments
 (0)