typed.List(Tuple(..)) inside njitted func does not compile

Hello. I need to create the temporary typed List with items of Tuple type:

L = List.empty_list(Tuple((int64, float64)))
L.append((1, 3.14))

This sample works in the python code, but not in the njitted-func:

@njit
def Test():
    L = List.empty_list(Tuple((int64, float64)))
    L.append((1, 3.14))
    return L[0]

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name ‘Tuple’: Cannot determine Numba type of <class ‘numba.core.types.abstract._TypeMetaclass’>

How can I make it work?

hi @zxweed , I think the problem lies in Tuple. Maybe try something like tup_type = Tuple((int64, float64)) outside the jitted function and then L = List.empty_list(tup_type) inside.

Hope this helps,
Luk

2 Likes

Thanks, @luk-f-a, this solution works.

@zxweed , since numba has type inference I could also do

@njit
def Test():
    L = []
    L.append((1, 3.14))
    return L[0]

@luk-f-a yes, but the numba developers have already announced that this method is considered deprecated

I think what’s deprecated is passing a python list as an input argument, not creating it inside the function. At least, that’s what I read from the description and the fact that running this code does not issue a deprecation warning.