Type hints for objmode


I’m trying to specify the types for objmode to work, but I can’t seem to be able to get it right.
Here’s a short example that summarizes what I need (not the actual code):

def numba_filter(k:int, ints:tuple):
    with objmode(filtered='???'):
        filtered = python_filter(k, ints)
    return np.array(filtered)

def python_filter(k, ints):
    return [(x,x) for x in ints if x < k]

I would normally type-hint filtered in regular python as List[Tuple[int]]. How do I do make it work here?

hi @ziofil ,

short answer: what you are looking for is "List(UniTuple(int64,2))" (as a string literal).

longer answer: Numba types can be found in numba.core.types. They use parenthesis instead of square brackets. You can import them and test them out as normal python objects. From the example above,

from numba.core import types
types.List(types.UniTuple(types.int64, 2)) # list(UniTuple(int64 x 2))<iv=None>

hope this helps,


Wonderful. Thank you so much!