# Buggy code
def unicode_strip(string, chars=None):
    unicode_strip_types_check(chars)

    def strip_impl(string, chars=None):
        lb = unicode_strip_left_bound(string, chars)
        rb = unicode_strip_right_bound(string, chars)
        return string[lb:rb]

    return strip_impl


# Traceback (NotImplementedError)
Traceback (most recent call last):
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 1032, in lower_expr
impl = self.context.get_function("static_getitem", signature)
File "/home/pearu/git/Quansight/numba/numba/targets/base.py", line 551, in get_function
return self.get_function(fn, sig, _firstcall=False)
File "/home/pearu/git/Quansight/numba/numba/targets/base.py", line 553, in get_function
raise NotImplementedError("No definition for lowering %s%s" % (key, sig))
NotImplementedError: No definition for lowering static_getitem(array([unichr x 1], 1d, C), Literal[int](0)) -> [unichr x 1]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/pearu/git/Quansight/numba/numba/errors.py", line 662, in new_error_context
yield
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 258, in lower_block
self.lower_inst(inst)
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 301, in lower_inst
val = self.lower_assign(ty, inst)
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 459, in lower_assign
return self.lower_expr(ty, value)
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 1041, in lower_expr
expr.index_var, signature)
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 600, in lower_getitem
res = impl(self.builder, castvals)
File "/home/pearu/git/Quansight/numba/numba/targets/base.py", line 1132, in __call__
res = self._imp(self._context, builder, self._sig, args, loc=loc)
File "/home/pearu/git/Quansight/numba/numba/targets/base.py", line 1157, in wrapper
return fn(*args, **kwargs)
File "/home/pearu/git/Quansight/numba/numba/targets/arrayobj.py", line 422, in getitem_arraynd_intp
aryty, ary, (idxty,), (idx,))
File "/home/pearu/git/Quansight/numba/numba/targets/arrayobj.py", line 406, in _getitem_array_generic
return load_item(context, builder, aryty, dataptr)
File "/home/pearu/git/Quansight/numba/numba/targets/arrayobj.py", line 127, in load_item
align=align)
File "/home/pearu/git/Quansight/numba/numba/targets/base.py", line 492, in unpack_value
return dm.load_from_data_pointer(builder, ptr, align)
File "/home/pearu/git/Quansight/numba/numba/datamodel/models.py", line 87, in load_from_data_pointer
return self.from_data(builder, builder.load(ptr, align=align))
File "/home/pearu/git/Quansight/numba/numba/datamodel/models.py", line 70, in from_data
raise NotImplementedError(self)
NotImplementedError: <numba.datamodel.models.UnicodeCharSeq object at 0x7f8674a8c400>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "bug_lowering_unicodecharseq.py", line 8, in <module>
foo(np.array(['a']))
File "/home/pearu/git/Quansight/numba/numba/dispatcher.py", line 395, in _compile_for_args
raise e
File "/home/pearu/git/Quansight/numba/numba/dispatcher.py", line 352, in _compile_for_args
return self.compile(tuple(argtypes))
File "/home/pearu/git/Quansight/numba/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/pearu/git/Quansight/numba/numba/dispatcher.py", line 693, in compile
cres = self._compiler.compile(args, return_type)
File "/home/pearu/git/Quansight/numba/numba/dispatcher.py", line 76, in compile
status, retval = self._compile_cached(args, return_type)
File "/home/pearu/git/Quansight/numba/numba/dispatcher.py", line 90, in _compile_cached
retval = self._compile_core(args, return_type)
File "/home/pearu/git/Quansight/numba/numba/dispatcher.py", line 108, in _compile_core
pipeline_class=self.pipeline_class)
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 972, in compile_extra
return pipeline.compile_extra(func)
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 390, in compile_extra
return self._compile_bytecode()
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 903, in _compile_bytecode
return self._compile_core()
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 890, in _compile_core
res = pm.run(self.status)
File "/home/pearu/git/Quansight/numba/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 266, in run
raise patched_exception
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 257, in run
stage()
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 764, in stage_nopython_backend
self._backend(lowerfn, objectmode=False)
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 703, in _backend
lowered = lowerfn()
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 690, in backend_nopython_mode
self.metadata)
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 1143, in native_lowering_stage
lower.lower()
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 177, in lower
self.lower_normal_function(self.fndesc)
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 218, in lower_normal_function
entry_block_tail = self.lower_function_body()
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 243, in lower_function_body
self.lower_block(block)
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 258, in lower_block
self.lower_inst(inst)
File "/home/pearu/mconda3/envs/numba-dev/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/home/pearu/git/Quansight/numba/numba/errors.py", line 670, in new_error_context
six.reraise(type(newerr), newerr, tb)
File "/home/pearu/git/Quansight/numba/numba/six.py", line 659, in reraise
raise value
numba.errors.LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
<numba.datamodel.models.UnicodeCharSeq object at 0x7f8674a8c400>

File "bug_lowering_unicodecharseq.py", line 6:
def foo(x):
return x[0]
^

[1] During: lowering "$0.3 = static_getitem(value=x, index=0, index_var=$const0.2)" at bug_lowering_unicodecharseq.py (6)
-------------------------------------------------------------------------------
This should not have happened, a problem has occurred in Numba's internals.
You are currently using Numba version 0.46.0dev0+43.g8b5726899.dirty.

# Fixed code
def unicode_strip(string, chars=None):
    if isinstance(chars, types.UnicodeCharSeq):

        def strip_impl(string, chars):
            return string.strip(str(chars))

        return strip_impl

    unicode_strip_types_check(chars)

    def strip_impl(string, chars=None):
        lb = unicode_strip_left_bound(string, chars)
        rb = unicode_strip_right_bound(string, chars)
        return string[lb:rb]

    return strip_impl