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

Code before:
                item = (PyArray_BYTES(self) + i * PyArray_STRIDES(self)[0]);
                if (PyArray_Pack(PyArray_DESCR(self), item, value) < 0) {
                    ret = -1;
                    goto finish_section;
                }
                /* If this was an array(-like) we still need to unlike int: */
                if (*cache != NULL && (*cache)->converted_obj == value) {
                    *cache = npy_unlink_coercion_cache(*cache);
                }
            }
            else {
                PyArrayObject *view;
                view = (PyArrayObject *)array_item_asarray(self, i);
                if (view == NULL) {
                    ret = -1;
                    goto finish_section;
                }
                if (PyArray_AssignFromCache_Recursive(view, ndim, cache) < 0) {
                    Py_DECREF(view);
                    ret = -1;
                    goto finish_section;
                }
                Py_DECREF(view);
            }
        }

    finish_section:;

        NPY_END_CRITICAL_SECTION_SEQUENCE_FAST();
    }
    Py_DECREF(obj);
    return ret;

  fail:
    Py_DECREF(obj);
    return -1;
}


/**
 * Fills an item based on a coercion cache object. It consumes the cache
 * object while doing so.
 *
 * @param self Array to fill.
 * @param cache coercion_cache_object, will be consumed. The cache must not
 *        contain a single array (must start with a sequence). The array case
 *        should be handled by `PyArray_FromArray()` before.
 * @return 0 on success -1 on failure.
 */
NPY_NO_EXPORT int
PyArray_AssignFromCache(PyArrayObject *self, coercion_cache_obj *cache) {

Review comment (bug):
Since I guess you might do the small other nits.  I have one more:

I might slightly prefer to start with `ret = -1` as the default and add `ret = 0` before the `finish_section:` part.
(We could then use the `return ret` for the `fail:` too, although it would be nicer as `finish:`.)

Code after:

            if (ndim == depth + 1) {
                /*
                 * Straight forward assignment of elements.  Note that it is
                 * possible for such an element to be a 0-D array or array-like.
                 * `PyArray_Pack` supports arrays as well as we want: We
                 * support exact NumPy arrays, but at this point ignore others.
                 * (Please see the `PyArray_Pack` function comment if this
                 * rightly confuses you.)
                 */
                char *item;
                item = (PyArray_BYTES(self) + i * PyArray_STRIDES(self)[0]);
                if (PyArray_Pack(PyArray_DESCR(self), item, item_pyvalue) < 0) {
                    goto finish_critical_section;
                }
                /* If this was an array(-like) we still need to unlike int: */
                if (*cache != NULL && (*cache)->converted_obj == item_pyvalue) {
                    *cache = npy_unlink_coercion_cache(*cache);
                }
            }
            else {
                PyArrayObject *view;
                view = (PyArrayObject *)array_item_asarray(self, i);
                if (view == NULL) {
                    goto finish_critical_section;
                }
                if (PyArray_AssignFromCache_Recursive(view, ndim, cache) < 0) {
                    Py_DECREF(view);
                    goto finish_critical_section;
                }
                Py_DECREF(view);
            }
        }
    err = 0;
      finish_critical_section:;

        NPY_END_CRITICAL_SECTION_SEQUENCE_FAST();
        if (err) {
            goto finish;
        }

    }
    ret = 0;

  finish:;
    Py_XDECREF(item_pyvalue);
    Py_DECREF(obj);
    return ret;
}