PyMemoize icon indicating copy to clipboard operation
PyMemoize copied to clipboard

Overload etag/etagger (and other potential pairs, e.g.: key/keyer)

Open mikeboers opened this issue 12 years ago • 2 comments

If we restrict the types that are allowed to be used as etags (and/or user-specified keys, see #4), then we could allow either a scalar etag or a function to create said etag to be passed via the same etag kwarg.

Potential set of types could be:

  • strings
  • ints
  • bools
  • None
  • tuples of these

Basically, hashable builtin types.

mikeboers avatar Feb 20 '13 22:02 mikeboers

Also, overload the methods on a decorated function to be used as decorators themselves:

@memo
def myfunc(a, b):
    pass

@myfunc.etag
def myfunc(a, b):
    return str((a, b))

Just need a relatively comprehensive iscallable to do the detection, since we have already declared that memoized callables may only use hashable arguments.

mikeboers avatar May 03 '13 16:05 mikeboers

Would be great if this would also support direct assignment:

myfunc.etag = common_etagger

mikeboers avatar Oct 25 '13 19:10 mikeboers