Created
April 12, 2018 11:07
-
-
Save Alphadelta14/37fc4ea0302738ea84d21f0de5ca0c9e to your computer and use it in GitHub Desktop.
Cython breaks passing kwargs to functions with one args
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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