Skip to content

Commit

Permalink
Merge pull request #110 from eriknw/fix/cimport_cytoolz
Browse files Browse the repository at this point in the history
Fix #101.  Modify how we handle curried `memoize` to make `cimport cytoolz work again.
  • Loading branch information
eriknw authored Dec 16, 2017
2 parents 33c7b18 + 1d78e85 commit e75c426
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ script:
# For convenience, make sure simple test commands work
- py.test
- nosetests
# Make sure we can cimport cytoolz
- echo 'cimport cytoolz ; from cytoolz.functoolz cimport memoize' > try_cimport_cytoolz.pyx
- cythonize -i try_cimport_cytoolz.pyx
- python -c 'import try_cimport_cytoolz'

notifications:
email: false
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ inplace:

test: inplace
nosetests -s --with-doctest cytoolz/
echo 'cimport cytoolz ; from cytoolz.functoolz cimport memoize' > try_cimport_cytoolz.pyx
cythonize -i try_cimport_cytoolz.pyx
python -c 'import try_cimport_cytoolz'
rm try_cimport_cytoolz.pyx

clean:
rm -f cytoolz/*.c cytoolz/*.so cytoolz/*/*.c cytoolz/*/*.so
Expand Down
6 changes: 5 additions & 1 deletion cytoolz/functoolz.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ cdef class curry:
cdef public object __module__
cdef public object __qualname__

cdef class memoize:

cpdef object memoize(object func, object cache=*, object key=*)


cdef class _memoize:
cdef object func
cdef object cache
cdef object key
Expand Down
14 changes: 7 additions & 7 deletions cytoolz/functoolz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,8 @@ cpdef object _restore_curry(cls, func, args, kwargs, is_decorated):
return obj


cdef class memoize:
""" memoize(func, cache=None, key=None)
cpdef object memoize(object func, object cache=None, object key=None):
"""
Cache a function's result for speedy future evaluation
Considerations:
Expand Down Expand Up @@ -414,6 +413,10 @@ cdef class memoize:
... print('Calculating %s + %s' % (x, y))
... return x + y
"""
return _memoize(func, cache, key)


cdef class _memoize:

property __doc__:
def __get__(self):
Expand All @@ -427,7 +430,7 @@ cdef class memoize:
def __get__(self):
return self.func

def __cinit__(self, func, cache=None, key=None):
def __cinit__(self, func, cache, key):
self.func = func
if cache is None:
self.cache = PyDict_New()
Expand Down Expand Up @@ -468,9 +471,6 @@ cdef class memoize:
return curry(self, instance)


_memoize = memoize # uncurried


cdef class Compose:
""" Compose(self, *funcs)
Expand Down

0 comments on commit e75c426

Please sign in to comment.