# Buggy code
def _unify_return_types(self, rettypes):
    if rettypes:
        unified = self.context.unify_types(*rettypes)
        if unified is None or not unified.is_precise():

            def check_type(atype):
                lst = []
                for k, v in self.typevars.items():
                    if atype == v.type:
                        lst.append(k)
                returns = {}
                for x in reversed(lst):
                    for block in self.func_ir.blocks.values():
                        for instr in block.find_insts(ir.Return):
                            value = instr.value
                            if isinstance(value, ir.Var):
                                name = value.name
                            else:
                                pass
                            if x == name:
                                returns[x] = instr
                                break

                for name, offender in returns.items():
                    loc = getattr(offender, "loc", "unknown location")
                    msg = "Return of: IR name '%s', type '%s', location: %s"
                    interped = msg % (name, atype, loc.strformat())
                return interped

            problem_str = []
            for xtype in rettypes:
                problem_str.append(_termcolor.errmsg(check_type(xtype)))

            raise TypingError(
                "Can't unify return type from the "
                "following types: %s"
                % ", ".join(sorted(map(str, rettypes)))
                + "\n"
                + "\n".join(problem_str)
            )
        return unified
    else:
        # Function without a successful return path
        return types.none


# Traceback (AttributeError)
Traceback (most recent call last):
File "examples/hello.py", line 25, in <module>
main()
File "examples/hello.py", line 19, in main
print(hpat(2))
File "numba/numba/dispatcher.py", line 367, in _compile_for_args
raise e
File "numba/numba/dispatcher.py", line 324, in _compile_for_args
return self.compile(tuple(argtypes))
File "numba/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "numba/numba/dispatcher.py", line 655, in compile
cres = self._compiler.compile(args, return_type)
File "numba/numba/dispatcher.py", line 82, in compile
pipeline_class=self.pipeline_class)
File "numba/numba/compiler.py", line 905, in compile_extra
return pipeline.compile_extra(func)
File "numba/numba/compiler.py", line 367, in compile_extra
return self._compile_bytecode()
File "numba/numba/compiler.py", line 836, in _compile_bytecode
return self._compile_core()
File "numba/numba/compiler.py", line 823, in _compile_core
res = pm.run(self.status)
File "numba/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "numba/numba/compiler.py", line 253, in run
raise patched_exception
File "numba/numba/compiler.py", line 244, in run
stage()
File "numba/numba/compiler.py", line 478, in stage_nopython_frontend
self.locals)
File "numba/numba/compiler.py", line 1009, in type_inference_stage
typemap, restype, calltypes = infer.unify()
File "numba/numba/typeinfer.py", line 924, in unify
check_var(var)
File "numba/numba/typeinfer.py", line 910, in check_var
raise TypingError(msg % (var, val, loc), loc)
File "numba/numba/errors.py", line 406, in __init__
highlight("%s\n%s\n" % (msg, loc.strformat())))
AttributeError: Failed in hpat mode pipeline (step: nopython frontend)
'str' object has no attribute 'strformat'

# Fixed code
def _unify_return_types(self, rettypes):
    if rettypes:
        unified = self.context.unify_types(*rettypes)
        if unified is None or not unified.is_precise():

            def check_type(atype):
                lst = []
                for k, v in self.typevars.items():
                    if atype == v.type:
                        lst.append(k)
                returns = {}
                for x in reversed(lst):
                    for block in self.func_ir.blocks.values():
                        for instr in block.find_insts(ir.Return):
                            value = instr.value
                            if isinstance(value, ir.Var):
                                name = value.name
                            else:
                                pass
                            if x == name:
                                returns[x] = instr
                                break

                for name, offender in returns.items():
                    loc = getattr(offender, "loc", ir.unknown_loc)
                    msg = "Return of: IR name '%s', type '%s', location: %s"
                    interped = msg % (name, atype, loc.strformat())
                return interped

            problem_str = []
            for xtype in rettypes:
                problem_str.append(_termcolor.errmsg(check_type(xtype)))

            raise TypingError(
                "Can't unify return type from the "
                "following types: %s"
                % ", ".join(sorted(map(str, rettypes)))
                + "\n"
                + "\n".join(problem_str)
            )
        return unified
    else:
        # Function without a successful return path
        return types.none