Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cython breaks passing kwargs to functions with one args
from __future__ import print_function
def func_one_arg(a):
print('one arg')
def func_one_kwarg(a=1):
print('one kwarg')
def func_two_args(a, b):
print('two args')
def func_two_kwargs(a=1, b=2):
print('two kwargs')
func_one_arg(1)
func_one_kwarg(1)
func_two_args(1, 2)
func_two_kwargs(1, 2)
try:
func_one_arg(a=1)
except:
print('Failed to run func_one_arg(a=1)')
func_one_kwarg(a=1)
func_two_args(a=1, b=2)
func_two_kwargs(a=1, b=2)
Running uncythonized code
one arg
one kwarg
two args
two kwargs
one arg
one kwarg
two args
two kwargs
Running cythonized code
one arg
one kwarg
two args
two kwargs
Failed to run func_one_arg(a=1)
one kwarg
two args
two kwargs
"""
cp cyargs.py cyargs2.py
cythonize cyargs2.py
gcc -shared -fPIC cyargs2.c -I/usr/local/include/python2.7 -o cyargs2.so -lpython2.7
python run_cyargs.py
"""
from __future__ import print_function
print('Running uncythonized code')
import cyargs
print()
print('Running cythonized code')
import cyargs2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.