Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'NoneType' object has no attribute 'args' #5896

Open
2 tasks done
nishio opened this issue Jun 20, 2020 · 3 comments
Open
2 tasks done

'NoneType' object has no attribute 'args' #5896

nishio opened this issue Jun 20, 2020 · 3 comments
Labels

Comments

@nishio
Copy link

nishio commented Jun 20, 2020

Reporting a bug

The following code:

from numba.pycc import CC


def main():
    ds = {1: (2, 3)}       # (A)
    x = ds.get(1, (4, 5))  # (B)
    # x = ds[1]            # (B2)
    y = x[1]               # (C)


cc = CC('my_module')
cc.export('main', '()')(main)
cc.compile()

produces the following error(digested):

numba.core.errors.LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
'NoneType' object has no attribute 'args'

File "t2.py", line 8:
def main():
    <source elided>
    # x = ds[1]            # (B2)
    y = x[1]               # (C)
    ^

During: lowering "$26binary_subscr.10 = static_getitem(value=x, index=1, index_var=$const24.9)" at t2.py (8)

Full stderr: https://gist.github.com/nishio/99eebe8011553025726a7730d2bef61f

If I use the line B2 instead of the line B, the error doesn't occur.

@esc esc added the needtriage label Jun 22, 2020
@esc
Copy link
Member

esc commented Jun 22, 2020

@nishio thank you for reporting this, we appreciate your input.

I can reproduce this and I can simplify this further:

from numba import njit


@njit
def main():
    ds = {1: (2, 3)}       # (A)
    x = ds.get(1, (4, 5))  # (B)
    #x = ds[1]            # (B2)
    y = x[1]               # (C)
    return y


print(main())

@esc
Copy link
Member

esc commented Jun 22, 2020

It does seem to work fine in the interpreter:

In [1]: from numba.typed import Dict
d
In [2]: d = Dict()

In [3]: d[1] = (2, 3)

In [4]: d.get(1, (4,5))
Out[4]: (2, 3)

In [5]: d.get(2, (4,5))
Out[5]: (4, 5)

Also, here is a more verbose reproducer that highlights the issue:

from numba import njit
from numba.typed import Dict


@njit
def foo(d):
    return d.get(1, (4, 5))


@njit
def bar(d):
    return d.get(1, (4, 5))[1]


d = Dict()
d[1] = (2, 3)

print(foo.py_func(d))
print(foo(d))

print(bar.py_func(d))
print(bar(d))

As you can see, the error occurs when we attempt to index into the tuple returned by get.

So, the problem is probably that get returns an OptionalType and that we then fail to index into that. Which is also what the error message here alludes to:

NotImplementedError: No definition for lowering static_getitem(OptionalType(UniTuple(int64 x 2)), Literal[int](1)) -> int64

@esc esc added bug and removed needtriage labels Jun 22, 2020
@esc
Copy link
Member

esc commented Jun 22, 2020

It may be possible to check that get does have a default in this case and therefore we can return a non-Optional type.

sklam added a commit to sklam/numba that referenced this issue Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants