Commit 0e0e2153 authored by Mark Dickinson's avatar Mark Dickinson

Warn against replacing PyNumber_Add with PyNumber_InPlaceAdd in sum

parent 828b3986
......@@ -2350,6 +2350,15 @@ builtin_sum(PyObject *self, PyObject *args)
}
break;
}
/* It's tempting to use PyNumber_InPlaceAdd instead of
PyNumber_Add here, to avoid quadratic running time
when doing 'sum(list_of_lists, [])'. However, this
would produce a change in behaviour: a snippet like
empty = []
sum([[x] for x in range(10)], empty)
would change the value of empty. */
temp = PyNumber_Add(result, item);
Py_DECREF(result);
Py_DECREF(item);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment