Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 140a7d1

Browse files
bpo-38378: Rename parameters "out" and "in" of os.sendfile(). (GH-16742)
They conflicted with keyword "in". Also rename positional-only parameters of private os._fcopyfile() for consistency.
1 parent 46113e0 commit 140a7d1

5 files changed

Lines changed: 39 additions & 34 deletions

File tree

Doc/library/os.rst

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,27 +1251,27 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
12511251
:exc:`InterruptedError` exception (see :pep:`475` for the rationale).
12521252

12531253

1254-
.. function:: sendfile(out, in, offset, count)
1255-
sendfile(out, in, offset, count, [headers], [trailers], flags=0)
1254+
.. function:: sendfile(out_fd, in_fd, offset, count)
1255+
sendfile(out_fd, in_fd, offset, count, [headers], [trailers], flags=0)
12561256

1257-
Copy *count* bytes from file descriptor *in* to file descriptor *out*
1257+
Copy *count* bytes from file descriptor *in_fd* to file descriptor *out_fd*
12581258
starting at *offset*.
1259-
Return the number of bytes sent. When EOF is reached return 0.
1259+
Return the number of bytes sent. When EOF is reached return ``0``.
12601260

12611261
The first function notation is supported by all platforms that define
12621262
:func:`sendfile`.
12631263

12641264
On Linux, if *offset* is given as ``None``, the bytes are read from the
1265-
current position of *in* and the position of *in* is updated.
1265+
current position of *in_fd* and the position of *in_fd* is updated.
12661266

12671267
The second case may be used on Mac OS X and FreeBSD where *headers* and
12681268
*trailers* are arbitrary sequences of buffers that are written before and
1269-
after the data from *in* is written. It returns the same as the first case.
1269+
after the data from *in_fd* is written. It returns the same as the first case.
12701270

1271-
On Mac OS X and FreeBSD, a value of 0 for *count* specifies to send until
1272-
the end of *in* is reached.
1271+
On Mac OS X and FreeBSD, a value of ``0`` for *count* specifies to send until
1272+
the end of *in_fd* is reached.
12731273

1274-
All platforms support sockets as *out* file descriptor, and some platforms
1274+
All platforms support sockets as *out_fd* file descriptor, and some platforms
12751275
allow other types (e.g. regular file, pipe) as well.
12761276

12771277
Cross-platform applications should not use *headers*, *trailers* and *flags*
@@ -1286,6 +1286,9 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
12861286

12871287
.. versionadded:: 3.3
12881288

1289+
.. versionchanged:: 3.9
1290+
Parameters *out* and *in* was renamed to *out_fd* and *in_fd*.
1291+
12891292

12901293
.. function:: set_blocking(fd, blocking)
12911294

Lib/test/test_os.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,11 +3110,12 @@ def test_invalid_offset(self):
31103110

31113111
def test_keywords(self):
31123112
# Keyword arguments should be supported
3113-
os.sendfile(out=self.sockno, offset=0, count=4096,
3114-
**{'in': self.fileno})
3113+
os.sendfile(out_fd=self.sockno, in_fd=self.fileno,
3114+
offset=0, count=4096)
31153115
if self.SUPPORT_HEADERS_TRAILERS:
3116-
os.sendfile(self.sockno, self.fileno, offset=0, count=4096,
3117-
headers=(), trailers=(), flags=0)
3116+
os.sendfile(out_fd=self.sockno, in_fd=self.fileno,
3117+
offset=0, count=4096,
3118+
headers=(), trailers=(), flags=0)
31183119

31193120
# --- headers / trailers tests
31203121

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Parameters *out* and *in* of :func:`os.sendfile` was renamed to *out_fd* and
2+
*in_fd*.

Modules/clinic/posixmodule.c.h

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

Modules/posixmodule.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8993,10 +8993,10 @@ os_write_impl(PyObject *module, int fd, Py_buffer *data)
89938993

89948994
#ifdef HAVE_SENDFILE
89958995
PyDoc_STRVAR(posix_sendfile__doc__,
8996-
"sendfile(out, in, offset, count) -> byteswritten\n\
8997-
sendfile(out, in, offset, count[, headers][, trailers], flags=0)\n\
8996+
"sendfile(out_fd, in_fd, offset, count) -> byteswritten\n\
8997+
sendfile(out_fd, in_fd, offset, count[, headers][, trailers], flags=0)\n\
89988998
-> byteswritten\n\
8999-
Copy count bytes from file descriptor in to file descriptor out.");
8999+
Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
90009000

90019001
/* AC 3.5: don't bother converting, has optional group*/
90029002
static PyObject *
@@ -9016,8 +9016,7 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
90169016
off_t sbytes;
90179017
struct sf_hdtr sf;
90189018
int flags = 0;
9019-
/* Beware that "in" clashes with Python's own "in" operator keyword */
9020-
static char *keywords[] = {"out", "in",
9019+
static char *keywords[] = {"out_fd", "in_fd",
90219020
"offset", "count",
90229021
"headers", "trailers", "flags", NULL};
90239022

@@ -9133,7 +9132,7 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
91339132
#else
91349133
Py_ssize_t count;
91359134
PyObject *offobj;
9136-
static char *keywords[] = {"out", "in",
9135+
static char *keywords[] = {"out_fd", "in_fd",
91379136
"offset", "count", NULL};
91389137
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiOn:sendfile",
91399138
keywords, &out, &in, &offobj, &count))
@@ -9170,22 +9169,22 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
91709169
/*[clinic input]
91719170
os._fcopyfile
91729171
9173-
infd: int
9174-
outfd: int
9172+
in_fd: int
9173+
out_fd: int
91759174
flags: int
91769175
/
91779176
91789177
Efficiently copy content or metadata of 2 regular file descriptors (macOS).
91799178
[clinic start generated code]*/
91809179

91819180
static PyObject *
9182-
os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags)
9183-
/*[clinic end generated code: output=8e8885c721ec38e3 input=69e0770e600cb44f]*/
9181+
os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags)
9182+
/*[clinic end generated code: output=c9d1a35a992e401b input=1e34638a86948795]*/
91849183
{
91859184
int ret;
91869185

91879186
Py_BEGIN_ALLOW_THREADS
9188-
ret = fcopyfile(infd, outfd, NULL, flags);
9187+
ret = fcopyfile(in_fd, out_fd, NULL, flags);
91899188
Py_END_ALLOW_THREADS
91909189
if (ret < 0)
91919190
return posix_error();

0 commit comments

Comments
 (0)