Cythonized function with a single positional argument is not possible to call using argument name

Viewed 209

Long story short, I want to cythonize my python code and build .so files to hide it from the customer. Take this simple function:

def one_positional_argument(a):
    print(a)

and my setup.py which builds the .so file

from setuptools import setup, find_packages
from Cython.Build import cythonize

setup(
    name='tmp',
    version='1.0.0',
    packages=find_packages(),
    nthreads=3,
    ext_modules=cythonize(
        ["a.py"],
        compiler_directives={'language_level': 3},
        build_dir="output",
    ),
)

When I import the .so file and try to execute my function here is what happens:

one_positional_argument(1) # this prints 1 and works fine
one_positional_argument(a=1) # throws TypeError: one_positional_argument() takes no keyword arguments

There are multiple workarounds to this but I would like to know if I am doing anything wrong

Additional info: If I have a function with 2 positional arguments, or one positional and one with default value, everything works fine. The issue is present only with 1 positional argument.

1 Answers
Related