Numba jitclass TypeError with full traceback

38 views
Skip to first unread message

Duarte Stokes

unread,
Aug 27, 2021, 10:55:55 AM8/27/21
to Numba Public Discussion - Public
Hi there,

I am using Numba v0.54.0 and I would like to know how to get the full traceback when dealing with the following error (which occurs at runtime):

-------------------------------------

import numba as nb

optional_bool = nb.optional(nb.boolean)
spec = [('my_bool', optional_bool)]


@nb.experimental.jitclass(spec)
class Foo():

    def __init__(self) -> None:
        self.my_bool = None

    def my_method(self) -> None:
        print('Inside `my_method`')

        if self.my_bool:
            print('Inside `if` statement')


Foo_type = Foo.class_type.instance_type
wrapper_signature = Foo_type()
@nb.jit(wrapper_signature, nopython=True)
def wrapper():
    foo = Foo()
    foo.my_method()
    return foo

if __name__ == '__main__':
    wrapper()

-----------------------------------------

I get the following output:

Inside `my_method`
Traceback (most recent call last):
  File "test.py", line 29, in <module>
    wrapper()
TypeError: expected bool, got None


However, if at the last line of code I write instead wrapper.py_func(), the traceback goes a little bit further (into the jitclass method):

Traceback (most recent call last):
  File "test.py", line 29, in <module>
    wrapper.py_func()
  File "test.py", line 25, in wrapper
    foo.my_method()
  File "C:\Users\statt\anaconda3\lib\site-packages\numba\experimental\jitclass\boxing.py", line 60, in wrapper
    return method(*args, **kwargs)
TypeError: expected bool, got None

Still, I need much more feedback to pinpoint the problem, which in this example occurs at:

if self.my_bool: # Turns out self.my_bool is None

Could someone give me a hand?

Thanks in advance!

Reply all
Reply to author
Forward
0 new messages