Pythran export dict with tuples as key

I try to use Pythran in a function that needs an int array and for the second arg a dict with tuples of ints as keys and an int as value:

myarray = np.array([[0, 0], [0, 1], [1, 1],
                    [1, 2], [2, 2], [1, 3]])

dict_with_tuples_key = {(0, 1): 1, (3, 7): 1}

What is the correct way to inform Pythran about the dict ?:

#pythran export update_dict((int, int):int dict, int[][])
def update_dict(dict_with_tuples_key, myarray):
    # do something with dict_with_tuples_key and myarray
    # return and updated dict_with_tuples_key
    return dict_with_tuples_key

With (int, int):int dict I get this error:

File "/usr/lib/python2.7/inspect.py", line 526, in findsource
  file = getfile(object)
File "/usr/lib/python2.7/inspect.py", line 403, in getfile
  raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module 'sys' (built-in)> is a built-in module

Answers

From your backtrace, it seems you're importing sys. In that kind of situation, pythran tries to get the source of the import module to compile it. As sys is a built-in module, it fails.

Posted on by serge-sans-paille

Relevant tags