# Buggy code
def dispatch_to_extension_op(op, left, right):
    """
    Assume that left or right is a Series backed by an ExtensionArray,
    apply the operator defined by op.
    """

    # The op calls will raise TypeError if the op is not defined
    # on the ExtensionArray
    # TODO(jreback)
    # we need to listify to avoid ndarray, or non-same-type extension array
    # dispatching

    if is_extension_array_dtype(left):
        new_left = left.values
        if isinstance(right, np.ndarray):
            # handle numpy scalars, this is a PITA
            # TODO(jreback)
            new_right = lib.item_from_zerodim(right)
            if is_scalar(new_right):
                new_right = [new_right]
            new_right = list(new_right)
        elif is_extension_array_dtype(right) and type(left) != type(right):
            new_right = list(new_right)
        else:
            new_right = right

    else:
        new_left = list(left.values)
        new_right = right

    res_values = op(new_left, new_right)
    res_name = get_op_result_name(left, right)

    if op.__name__ == "divmod":
        return _construct_divmod_result(left, res_values, left.index, res_name)

    return _construct_result(left, res_values, left.index, res_name)


# Traceback (UnboundLocalError)
In [41]: s
Out[41]:
0    1
1    2
2    3
dtype: Int64

In [42]: s.values
Out[42]: IntegerArray([1, 2, 3], dtype='Int64')

In [43]: s + s.values
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-43-c3f015376225> in <module>()
----> 1 s + s.values

C:\Users\Public\pandas-peter\pandas\core\ops.py in wrapper(left, right)
1231                 (is_extension_array_dtype(right) and not is_scalar(right
))):
1232             # GH#22378 disallow scalar to exclude e.g. "category", "Int6
4"
-> 1233             return dispatch_to_extension_op(op, left, right)
1234
1235         elif is_datetime64_dtype(left) or is_datetime64tz_dtype(left):

C:\Users\Public\pandas-peter\pandas\core\ops.py in dispatch_to_extension_op(op,
left, right)
1152             new_right = list(new_right)
1153         elif is_extension_array_dtype(right) and type(left) != type(righ
t):
-> 1154             new_right = list(new_right)
1155         else:
1156             new_right = right

UnboundLocalError: local variable 'new_right' referenced before assignment

# Fixed code
def dispatch_to_extension_op(op, left, right):
    """
    Assume that left or right is a Series backed by an ExtensionArray,
    apply the operator defined by op.
    """

    # The op calls will raise TypeError if the op is not defined
    # on the ExtensionArray
    # TODO(jreback)
    # we need to listify to avoid ndarray, or non-same-type extension array
    # dispatching

    if is_extension_array_dtype(left):
        new_left = left.values
        if isinstance(right, np.ndarray):
            # handle numpy scalars, this is a PITA
            # TODO(jreback)
            new_right = lib.item_from_zerodim(right)
            if is_scalar(new_right):
                new_right = [new_right]
            new_right = list(new_right)
        elif is_extension_array_dtype(right) and type(left) != type(right):
            new_right = list(right)
        else:
            new_right = right

    else:
        new_left = list(left.values)
        new_right = right

    res_values = op(new_left, new_right)
    res_name = get_op_result_name(left, right)

    if op.__name__ == "divmod":
        return _construct_divmod_result(left, res_values, left.index, res_name)

    return _construct_result(left, res_values, left.index, res_name)