Skip to content

Instantly share code, notes, and snippets.

@Alphadelta14
Created April 12, 2018 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alphadelta14/37fc4ea0302738ea84d21f0de5ca0c9e to your computer and use it in GitHub Desktop.
Save Alphadelta14/37fc4ea0302738ea84d21f0de5ca0c9e to your computer and use it in GitHub Desktop.
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