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,6 +34,7 @@ def memoize_default(default=None, evaluator_is_first_arg=False, second_arg_is_ev
if key in memo:
return memo[key]
else:
if default is not NO_DEFAULT:
memo[key] = default
rv = function(obj, *args, **kwargs)
memo[key] = rv

View File

@@ -27,7 +27,7 @@ from jedi.evaluate import helpers
from jedi import settings
from jedi.common import source_to_unicode
from jedi.evaluate import compiled
from jedi.evaluate.cache import memoize_default
from jedi.evaluate.cache import memoize_default, NO_DEFAULT
class ModuleNotFound(Exception):
@@ -290,7 +290,7 @@ class _Importer(object):
return evaluator.follow_path(iter(rest), [scope], scope)
return [scope]
@memoize_default()
@memoize_default(NO_DEFAULT)
def follow_file_system(self):
if self.file_path:
sys_path_mod = list(self.sys_path_with_modifications())

View File

@@ -303,3 +303,17 @@ recurse_class1.C.a
# github #239 RecursionError
#? ['a']
recurse_class1.C().a
# -----------------
# Jedi debugging
# -----------------
# memoizing issues (check git history for the fix)
import not_existing_import
if not_existing_import:
a = not_existing_import
else:
a = not_existing_import
#?
a