Moved into a function for testability.

def make_set_closure_cell():
    """
    Moved into a function for testability.
    """
    if PYPY:  # pragma: no cover

        def set_closure_cell(cell, value):
            cell.__setstate__((value,))

    else:
        try:
            ctypes = import_ctypes()

            set_closure_cell = ctypes.pythonapi.PyCell_Set
            set_closure_cell.argtypes = (ctypes.py_object, ctypes.py_object)
            set_closure_cell.restype = ctypes.c_int
        except Exception:
            # We try best effort to set the cell, but sometimes it's not
            # possible.  For example on Jython or on GAE.
            set_closure_cell = just_warn
    return set_closure_cell