The slash "/" as used in the documentation
Ian Kelly
ian.g.kelly at gmail.com
Mon Feb 11 02:47:14 EST 2019
On Mon, Feb 11, 2019 at 12:19 AM Terry Reedy <tjreedy at udel.edu> wrote:
> The pass-by-position limitation is not in CPython, it is the behavior of
> C functions, which is the behavior of function calls in probably every
> assembly and machine language. Allowing the flexibility of Python
> function calls take extra code and slows function calls.
>
> math.sin, for instance, is a fast-as-possible wrapper around the C math
> library sin function. It extracts the C double from the Python float,
> calls C sin, and returns the returned C double wrapped as a Python
> float. Coredevs decided that being able to call math.sin(x=.33333) is
> not worth the resulting slowdown. I am rather sure that heavy users of
> the math module would agree.
For math.sin, sure, but what about, say, list.index? Here's the start
of the implementation:
static PyObject *
listindex(PyListObject *self, PyObject *args)
{
Py_ssize_t i, start=0, stop=Py_SIZE(self);
PyObject *v;
if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
_PyEval_SliceIndex, &start,
_PyEval_SliceIndex, &stop))
This is already paying the cost of not using C-style positional
function arguments, but then it only takes an argument tuple, so it
can't take keyword arguments anyway. Why? Wouldn't it be nice to be
able to write:
mylist.index(42, start=10, stop=99)
instead of:
mylist.index(42, 10, 99)
This would also allow stop to be passed alone:
mylist.index(42, stop=99)
rather than having to pass the default value for start explicitly just
so we can pass stop:
mylist.index(42, 0, 99)
More information about the Python-list
mailing list