Repository: numpy/numpy
File: numpy/_core/src/multiarray/iterators.c (C)

Code before:
static PyObject*
arraymultiter_new(PyTypeObject *NPY_UNUSED(subtype), PyObject *args,
                  PyObject *kwds)
{
    PyObject *ret, *fast_seq;
    Py_ssize_t n;

    if (kwds != NULL && PyDict_Size(kwds) > 0) {
        PyErr_SetString(PyExc_ValueError,
                        "keyword arguments not accepted.");
        return NULL;
    }
    fast_seq = PySequence_Fast(args, "");  // noqa: borrowed-ref OK
    if (fast_seq == NULL) {
        return NULL;
    }
    NPY_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST_NO_BRACKETS(args, multiter_cs)
    n = PySequence_Fast_GET_SIZE(fast_seq);
    if (n > NPY_MAXARGS) {
        Py_DECREF(fast_seq);
        NPY_END_CRITICAL_SECTION_SEQUENCE_FAST_NO_BRACKETS(multiter_cs)
        return multiiter_wrong_number_of_args();
    }
    ret = multiiter_new_impl(n, PySequence_Fast_ITEMS(fast_seq));
    Py_DECREF(fast_seq);
    NPY_END_CRITICAL_SECTION_SEQUENCE_FAST_NO_BRACKETS(multiter_cs)
    return ret;
}

static PyObject *
arraymultiter_next(PyArrayMultiIterObject *multi)
{
    PyObject *ret;
    int i, n;

    n = multi->numiter;
    ret = PyTuple_New(n);
    if (ret == NULL) {
        return NULL;
    }
    if (multi->index < multi->size) {
        for (i = 0; i < n; i++) {
            PyArrayIterObject *it=multi->iters[i];
            PyTuple_SET_ITEM(ret, i,
                             PyArray_ToScalar(it->dataptr, it->ao));
            PyArray_ITER_NEXT(it);
        }
        multi->index++;
        return ret;
    }
    Py_DECREF(ret);

Review comment (suggestion):
(If you like) Just realized that we could use `if () {} else {}` here rather than the no-brackets thing, even if I really prefer this pattern for error returns to keep indentation shorter in general.

(Also simplifies the `Py_DECREF(fast_seq)` a bit in this instance.)

Code after:
static PyObject*
arraymultiter_new(PyTypeObject *NPY_UNUSED(subtype), PyObject *args,
                  PyObject *kwds)
{
    PyObject *ret, *fast_seq;
    Py_ssize_t n;

    if (kwds != NULL && PyDict_Size(kwds) > 0) {
        PyErr_SetString(PyExc_ValueError,
                        "keyword arguments not accepted.");
        return NULL;
    }
    fast_seq = PySequence_Fast(args, "");  // noqa: borrowed-ref OK
    if (fast_seq == NULL) {
        return NULL;
    }
    NPY_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST(fast_seq)
    n = PySequence_Fast_GET_SIZE(fast_seq);
    if (n > NPY_MAXARGS) {
        ret = multiiter_wrong_number_of_args();
    } else {
        ret = multiiter_new_impl(n, PySequence_Fast_ITEMS(fast_seq));
    }
    Py_DECREF(fast_seq);
    NPY_END_CRITICAL_SECTION_SEQUENCE_FAST()
    return ret;
}

static PyObject *
arraymultiter_next(PyArrayMultiIterObject *multi)
{
    PyObject *ret;
    int i, n;

    n = multi->numiter;
    ret = PyTuple_New(n);
    if (ret == NULL) {
        return NULL;
    }
    if (multi->index < multi->size) {
        for (i = 0; i < n; i++) {
            PyArrayIterObject *it=multi->iters[i];
            PyTuple_SET_ITEM(ret, i,
                             PyArray_ToScalar(it->dataptr, it->ao));
            PyArray_ITER_NEXT(it);
        }
        multi->index++;
        return ret;
    }
    Py_DECREF(ret);
    return NULL;