Hey Numba team,
I’m encountering an issue while trying to use an IntEnum as an optional argument in a jitted function. Whenever I attempt to pass an IntEnum member as an optional argument, I get a TypeError: '>' not supported between instances of 'Conversion' and 'NoneType'
. Explicit casting into an integer doesn’t seem to be supported.
from enum import IntEnum
import numba as nb
class Number(IntEnum):
ONE = 1
TWO = 2
THREE = 3
@nb.njit(['i8(i8, i8)', 'i8(i8, Omitted(None))'])
def add(a, b=None):
b = b or Number.ONE
return a+b
print('add(1, 1) => ', add(1, 1))
print('add(1) => ', add(1))
print('add(1, Number.ONE) => ', add(1, Number.ONE))
# add(1, 1) -> 2
# add(1) -> 2
# TypeError: '>' not supported between instances of 'Conversion' and 'NoneType'
Surprisingly, if you’ve previously called a function that uses IntEnum as an ordinary argument, you can then use the IntEnum as an optional argument, too.
from enum import IntEnum
import numba as nb
class Number(IntEnum):
ONE = 1
TWO = 2
THREE = 3
@nb.njit(['i8(i8, i8)'])
def add_dummy(a, b):
return a+b
add_dummy(1, 1)
add_dummy(1, Number.ONE)
@nb.njit(['i8(i8, i8)', 'i8(i8, Omitted(None))'])
def add(a, b=None):
b = b or Number.ONE
return a+b
print('add(1, 1) => ', add(1, 1))
print('add(1) => ', add(1))
print('add(1, Number.ONE) => ', add(1, Number.ONE))
# add(1, 1) -> 2
# add(1) -> 2
# add(1, Number.ONE) => 2
Is there a way to provide sufficient type hints and prevent the TypeError?