Problem description

TypeError: Test () Tasks no keyword arguments TypeError: Test () Tasks no keyword arguments

For local replay, prepare a simple function and a setup.py for packaging

├── ├─ ├.py ├── ├.pyCopy the code

test.py

def test(uid) :
    print(uid)


if __name__ == "__main__":
    test(uid=321)
Copy the code

setup.py

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules=cythonize('test.py',language_level=3)),Copy the code

The result is as follows

Problem solving

Remember, there was a PEP that said that limits can only be positional parameters, but I don’t have any limits in my function, and that shouldn’t happen.

Then in the group to seek help, there is a warm old brother to give a link: github.com/cython/cyth…

Basically, this is Cython’s “optimization” of single-argument functions, and you need to specify compilation parameters if you want to avoid this.

Then modify according to the solution mentioned in the ISSUE

# setup.py
from distutils.core import setup
from Cython.Build import cythonize


setup(
    ext_modules=cythonize(
        'test.py',
        language_level=3,
        compiler_directives={"always_allow_keywords": True}),)Copy the code

Note line 10, which avoids Cython’s optimization of single-argument functions.

After modification, compile and run again, the result is as follows

Problem solved.

conclusion

Your problems are likely shared by others, so don’t shut your door. In their own thinking, searching, still can not solve the time, the courage to ask.

Don’t forget to thank someone for helping you, but more importantly, don’t forget to pass on the kindness: a word from you could save someone else a day. Why not?

The resources

  1. Github.com/cython/cyth…

  2. www.python.org/dev/peps/pe…

  3. Docs.cython.org/en/latest/s…