1
0
forked from VimPlug/jedi

memoize problems with defaults in combination with raised exceptions

This commit is contained in:
Dave Halter
2014-04-20 14:14:30 +02:00
parent 27f01ca1f6
commit 50c4b7bfd9
3 changed files with 20 additions and 3 deletions

View File

@@ -4,6 +4,8 @@
- ``CachedMetaClass`` uses ``memoize_default`` to do the same with classes.
"""
NO_DEFAULT = object()
def memoize_default(default=None, evaluator_is_first_arg=False, second_arg_is_evaluator=False):
""" This is a typical memoization decorator, BUT there is one difference:
@@ -32,7 +34,8 @@ def memoize_default(default=None, evaluator_is_first_arg=False, second_arg_is_ev
if key in memo:
return memo[key]
else:
memo[key] = default
if default is not NO_DEFAULT:
memo[key] = default
rv = function(obj, *args, **kwargs)
memo[key] = rv
return rv