How to indicate a list of dicts in pythran?

85 Views Asked by At

I don't know how to indicate a list of dicts in Pythran. Say I call the function dictest() in a pure python file. A list of dicts (here: ll) need to be provided as arguments:

import test_pythran as tp

dd = {
        "ux": 10.0,
        "uy": 5,
        "uz": 3.4
        }

ee = {
        "ux": 11.0,
        "uy": 7,
        "uz": 2.4
        }

ll = (dd,ee)

tp.dictest(ll)

The function dictest() is defined in a separate file (here: test.py), which is compiled by pythran test.py -o test_pythran.so:

#pythran export dictest(str:float dict list )

def dictest(ll):
    print(ll["ux"], ll["uy"], ll["uz"])

Compilation gives a bunch of errors:

WARNING: Compilation error, trying hard to find its origin...
Compilation error, trying hard to find its origin...
WARNING: Nope, I'm going to flood you with C++ errors!
Nope, I'm going to flood you with C++ errors!
CRITICAL: Cover me Jack. Jack? Jaaaaack!!!!
E: error: Command "/usr/local/opt/gcc/bin/g++-12 -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -DENABLE_PYTHON_MODULE -D__PYTHRAN__=3 -DPYTHRAN_BLAS_OPENBLAS -I/usr/local/opt/openblas/include -I/usr/local/Cellar/pythran/0.12.0/libexec/lib/python3.10/site-packages/pythran -I/usr/local/opt/numpy/lib/python3.10/site-packages/numpy/core/include -I/usr/local/Cellar/pythran/0.12.0/libexec/include -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c /var/folders/41/dj_cjw2977qbd4fqxf1c79tc0000gn/T/tmpctvfroxf.cpp -o /var/folders/41/dj_cjw2977qbd4fqxf1c79tc0000gn/T/tmp3ae2neiv/var/folders/41/dj_cjw2977qbd4fqxf1c79tc0000gn/T/tmpctvfroxf.o -std=c++11 -fno-math-errno -Wno-unused-function" failed with exit status 1
Cover me Jack. Jack? Jaaaaack!!!!
E: error: Command "/usr/local/opt/gcc/bin/g++-12 -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -DENABLE_PYTHON_MODULE -D__PYTHRAN__=3 -DPYTHRAN_BLAS_OPENBLAS -I/usr/local/opt/openblas/include -I/usr/local/Cellar/pythran/0.12.0/libexec/lib/python3.10/site-packages/pythran -I/usr/local/opt/numpy/lib/python3.10/site-packages/numpy/core/include -I/usr/local/Cellar/pythran/0.12.0/libexec/include -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c /var/folders/41/dj_cjw2977qbd4fqxf1c79tc0000gn/T/tmpctvfroxf.cpp -o /var/folders/41/dj_cjw2977qbd4fqxf1c79tc0000gn/T/tmp3ae2neiv/var/folders/41/dj_cjw2977qbd4fqxf1c79tc0000gn/T/tmpctvfroxf.o -std=c++11 -fno-math-errno -Wno-unused-function" failed with exit status 1

I am sure that it is related to the way I need to indicate the list of dicts in the function definition: str:float dict list. How to do this in the proper way?

Thanks!

1

There are 1 best solutions below

0
serge-sans-paille On

There are several issues in your example.

First, dictest takes a list of dict as input but you're indexing its argument through a string, maybe you meant

#pythran export dictest(str:float dict list )

def dictest(ll):
    for l in ll:
        print(l["ux"], l["uy"], l["uz"])

Second, at call site you're passing a tuple of dict and not a list of dict as input to dictest. You probably wants to type

ll = [dd, ee]