Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Proper syntax for decorators with arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed Nov 12, 2020
1 parent a9a758c commit fc23e73
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/sage/misc/cachefunc.pyx
Expand Up @@ -1243,8 +1243,11 @@ cdef class CachedFunction(object):
for ((args,kwargs), val) in P(arglist2):
self.set_cache(val, *args, **kwargs)

def cached_function(func, classmethod=False, name=None, key=None, do_pickle=None):
return decorate(func, CachedFunction(func, classmethod=classmethod, name=name, key=key, do_pickle=do_pickle))

def cached_function(classmethod=False, name=None, key=None, do_pickle=None):
def deco(func):
return decorate(func, CachedFunction(func, classmethod=classmethod, name=name, key=key, do_pickle=do_pickle))
return deco


cdef class WeakCachedFunction(CachedFunction):
Expand Down Expand Up @@ -1433,8 +1436,11 @@ cdef class WeakCachedFunction(CachedFunction):
self.cache = CachedWeakValueDictionary(**kwds)


def weak_cached_function(func, classmethod=False, name=None, key=None, **kwds):
return decorate(func, WeakCachedFunction(func, classmethod=classmethod, name=name, key=key, **kwds))
def weak_cached_function(classmethod=False, name=None, key=None, **kwds):
def deco(func)
return decorate(func, WeakCachedFunction(func, classmethod=classmethod, name=name, key=key, **kwds))
return deco


class CachedMethodPickle(object):
"""
Expand Down Expand Up @@ -3304,8 +3310,11 @@ cdef class CachedInParentMethod(CachedMethod):
pass
return Caller

def cached_in_parent_method(func, name=None, key=None, do_pickle=None):
return decorate(func, CachedInParentMethod(func, name, key, do_pickle))

def cached_in_parent_method(name=None, key=None, do_pickle=None):
def deco(func):
return decorate(func, CachedInParentMethod(func, name, key, do_pickle))
return deco


class FileCache(object):
Expand Down

0 comments on commit fc23e73

Please sign in to comment.