Problem with Typed List function argument


I have a simple function that I would like to njit in numba that takes a list of strings as the argument and returns a tuple of int and bool. The problem is with the function argument. When I do the following:

@njit(types.Tuple((types.int32, types.boolean))(types.List(types.unicode_type,True)))
def func(items: list[str]) -> tuple[int, bool]:
    return len(items), 'apple' in items

print(func(["apple", "orange", "banana"])) #(3, True)

I get the warning:

Encountered the use of a type that is scheduled for deprecation: type 'reflected list' found for argument 'lst' of function 'in_seq.<locals>.seq_contains_impl'.

For more information visit

def in_seq(context, builder, sig, args):
    def seq_contains_impl(lst, value):

  warnings.warn(NumbaPendingDeprecationWarning(msg, loc=loc))

However when I change it to use typed.List below:

from numba import njit, types, typed

@njit(types.Tuple((types.int32, types.boolean))(typed.List(types.unicode_type)))
def func(items: list[str]) -> tuple[int, bool]:
    return len(items), 'apple' in items

print(func(["apple", "orange", "banana"]))

I get:

KeyError: 'Can only index numba types with slices with no start or stop, got 0.'

What should I do in this situation?

My numba version is 0.58.0 and the Python version is Python 3.9.17 and am using a Mac Book Pro with an M1 chip

Hey @edfink234 ,
Numba allows reflected and typed lists as arguments.
Using reflected lists you will receive a DeprecationWarning.
You can switch off the warning when you generate the jitted function if you need to use reflected lists.
If you want to use typed list the correct definition would be ListType(unicode_type).

import warnings
import numba as nb
import numba.types as nbt
from numba.core.errors import NumbaDeprecationWarning, NumbaPendingDeprecationWarning

def pyfunc(items: list[str]) -> tuple[int, bool]:
    return len(items), 'apple' in items

typeReflectedList = nbt.List(nbt.unicode_type, True)
typeTypedList = nbt.ListType(nbt.unicode_type)
signature = [nbt.Tuple((nbt.int32, nbt.boolean))(typeReflectedList),
             nbt.Tuple((nbt.int32, nbt.boolean))(typeTypedList)]

with warnings.catch_warnings():
    warnings.simplefilter('ignore', category=NumbaDeprecationWarning)
    warnings.simplefilter('ignore', category=NumbaPendingDeprecationWarning)
    jitfunc = nb.njit(signature)(pyfunc)

myReflectedList = ["apple", "orange", "banana"]
myTypedList = nb.typed.List(myReflectedList)
# (3, True)
# (3, True)