# Buggy code
def get_parfor_reductions(parfor):
    """get variables that are accumulated using inplace_binop inside the parfor
    and need to be passed as reduction parameters to gufunc.
    """
    last_label = max(parfor.loop_body.keys())
    reductions = {}
    names = []
    parfor_params = get_parfor_params(parfor)
    for blk in parfor.loop_body.values():
        for stmt in blk.body:
            if (
                isinstance(stmt, ir.Assign)
                and isinstance(stmt.value, ir.Expr)
                and stmt.value.op == "inplace_binop"
            ):
                name = stmt.value.lhs.name
                if name in parfor_params:
                    names.append(name)
                    reductions[name] = (stmt.value.fn, stmt.value.immutable_fn)
    return sorted(names), reductions


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def get_parfor_reductions(parfor, parfor_params, reductions=None, names=None):
    """get variables that are accumulated using inplace_binop inside the parfor
    and need to be passed as reduction parameters to gufunc.
    """
    if reductions is None:
        reductions = {}
    if names is None:
        names = []
    last_label = max(parfor.loop_body.keys())

    for blk in parfor.loop_body.values():
        for stmt in blk.body:
            if (
                isinstance(stmt, ir.Assign)
                and isinstance(stmt.value, ir.Expr)
                and stmt.value.op == "inplace_binop"
            ):
                name = stmt.value.lhs.name
                if name in parfor_params:
                    names.append(name)
                    red_info = None
                    for acc_op, imm_op, init_val in _reduction_ops.values():
                        if imm_op == stmt.value.immutable_fn:
                            red_info = (
                                stmt.value.fn,
                                stmt.value.immutable_fn,
                                init_val,
                            )
                            break
                    if red_info is None:
                        raise NotImplementedError(
                            "Reduction is not support for inplace operator %s"
                            % stmt.value.fn
                        )
                    reductions[name] = red_info
            if isinstance(stmt, Parfor):
                # recursive parfors can have reductions like test_prange8
                get_parfor_reductions(stmt, parfor_params, reductions, names)
    return names, reductions